title: Get rows with max value having 3 columns
body: <p>I have this PL/SQL query:</p>
  
  <pre><code>SELECT customer_id, table_id, count(table_id) as reserved
  FROM { derived table }
  GROUP BY customer_id,table_id
  ORDER BY reserved DESC
  </code></pre>
  
  <p>I have this result:</p>
  
  <p><a href="http://i.stack.imgur.com/ATfUw.png" rel="nofollow">http://i.stack.imgur.com/ATfUw.png</a></p>
  
  <p>So now I want to get the first 2 rows (with max value according to <code>reserved</code> column), I tried this query:</p>
  
  <pre><code>SELECT customer_id,table_id,max(reserved) from
  (
      SELECT customer_id, table_id, count(table_id) as reserved
      FROM { derived table }
      GROUP BY customer_id,table_id
      ORDER BY reserved DESC
  )
  GROUP BY customer_id, table_id
  </code></pre>
  
  <p>I recieved same result as above...</p>
  
  <p><strong>Note:</strong> Result was just example, maybe there will be 3, 1 or more rows with max value, next time</p>