Suppose I have a table named items:
sender_id receiver_id goods_id price
2 1 a1 1000
3 1 b2 2000
2 1 c1 5000
4 1 d1 700
2 1 b1 500
Here I want to select sender_id, goods_id in descending order of price from the items table , so that the row is not displayed more than once, which contains the same sender_id value (here sender_id 2). I used the following query, but was in vain:
select distinct sender_id,goods_id from items where receiver_id=1 order by price desc
The result shows all five tuples (records) with tuples containing sender_id 2 three times in decreasing order of time. But I want to display only three records, one of which has sender_id of 2 with the highest price of 5000. What should I do? My expected result:
sender_id goods_id
2 c1
3 b2
4 d1
source
share