title: SQL query taking "too" long - select with distinct and max
body: <p>I have the scenario:</p>
  
  <p>A table with POSITION and a value associated for each position, BUT I have always 4 values for the same position, so an example of my table is:</p>
  
  <pre><code>position | x| values 
  1 | x1 | 0
  1 | x2 | 1
  1 | x3 | 1.4
  1 | x4 | 2
  2 | x1 | 3
  2 | x2 | 10
  2 | x3 | 12.4
  2 | x4 | 22
  </code></pre>
  
  <p>I need a query that returns me the MAX value for each unique position value. Now, I am querying it with:</p>
  
  <pre><code>SELECT DISTINCT (position) AS p, (SELECT MAX(values) AS v FROM MYTABLE  WHERE position = p) FROM MYTABLE;
  </code></pre>
  
  <p>It took me 1651 rows in set (39.93 sec), and 1651 rows is just a test for this database (it probably should have more then 1651 rows.</p>
  
  <p>What am I doing wrong ? are there any better way to get it in a faster way ?</p>
  
  <p>Any help is appreciated.
  Cheers.,</p>