title: Mysql MIN() Max() function with JOIN and GROUP BY
body: <p>i have a problem, i need to find MIN() and MAX() with JOIN and GROUP BY with Mysql.</p>
  
  <p>I have 3 tables :</p>
  
  <ul>
  <li>Parent(parent_id) </li>
  <li>Child(child_id, parent_id) </li>
  <li>Price(price_id, child_id, price)</li>
  </ul>
  
  <p>One parent can have many childs, and a child has only one price.</p>
  
  <p>Here is my query to get all prices of a Parent:</p>
  
  <pre><code>select   child.parent_id ,  price.child_id  , price.price
  from parent 
   inner join  child on child.parent_id = parent.id 
   inner join price on price.child_id = child.id
  </code></pre>
  
  <p>I want to find the min price of a Parent. But i don't want only the price, i want the price_id ! </p>
  
  <p>Can you help me to make this query to find the price_id of the min() price of each parent ?</p>
  
  <p>Here are data samples :</p>
  
  <pre><code>parent1 : parent_id=1
  parent2 : parent_id=2
  
  child1 : child_id=1 , parent_id=1
  child2 : child_id=2 , parent_id=1
  child3 : child_id=3 , parent_id=1
  
  child4 : child_id=4 , parent_id=2
  child5 : child_id=5 , parent_id=2
  child6 : child_id=6 , parent_id=2
  
  price1 : price_id=1 , child_id=1, price=15
  price2 : price_id=2 , child_id=2, price=5
  price3 : price_id=3 , child_id=3, price=10
  
  price4 : price_id=4 , child_id=4, price=10
  price5 : price_id=5 , child_id=5, price=20
  price6 : price_id=6 , child_id=6, price=30
  </code></pre>
  
  <p>I want to find for parent1 the id of the min price of his childs, the result is : price_id=2</p>
  
  <p>I want to find for parent2 the id of the min price of his childs, the result is : price_id=4</p>
  
  <p>I want to find for parent1 the id of the MAX price of his childs, the result is : price_id=1</p>
  
  <p>I want to find for parent2 the id of the MAX price of his childs, the result is : price_id=6</p>
  
  <p>Thank you !</p>