title: Postgres: GROUP BY several column
body: <p>I have two table in this example.</p>
  
  <p>( example column name )</p>
  
  <p>First is the product </p>
  
  <pre><code>product_id | product_text
  </code></pre>
  
  <p>Second table is Price.</p>
  
  <pre><code>price_productid | price_datestart | price_price
  </code></pre>
  
  <p>Let's just say I have multiple datestart with the same product. How can I get the actual price ?</p>
  
  <p>If I use GROUP BY in Postgres, with all the selected column, 2 row may come for the same product. Because the column price_datestart is different.</p>
  
  <p>Example :</p>
  
  <pre><code>product_id : 1
  product_text : "Apple Iphone"
  
  
  price_productid : 1
  price_datestart :"2013-10-01"
  price_price :"99"
  
  
  price_productid : 1
  price_datestart :"2013-12-01"
  price_price :"75"
  </code></pre>
  
  <p>If I try this :</p>
  
  <pre><code>SELECT price_productid,price_datestart,price_price,product_text,product_id
  WHERE price_datestart &gt; now()
  GROUP BY price_productid,price_datestart,price_price,product_text,product_id
  ORDER BY price_datestart ASC
  </code></pre>
  
  <p>It will give me a result, but two rows and I need one.</p>