Selecting rows distinctively
Posted
by
noway
on Stack Overflow
See other posts from Stack Overflow
or by noway
Published on 2012-09-05T21:36:31Z
Indexed on
2012/09/05
21:37 UTC
Read the original article
Hit count: 168
Lets assume my database table structure is something like
| items | weight |
|============|==========|
| item_1 | 50 |
| item_2 | 90 |
| item_2 | 45 |
| item_2 | 60 |
| item_3 | 40 |
In the select statement, I want to show an item only for once with the highest weight also ordered by height. So the result should be :
| items | weight |
|============|==========|
| item_2 | 90 |
| item_1 | 50 |
| item_3 | 40 |
I tried something like
SELECT DISTINCT items, weight FROM mytable ORDER BY weight DESC
but it didn't work because the results are actually distinct.
How can I make that selection?
© Stack Overflow or respective owner