开发者

How do I use a select query to get the least of one value for each unique second value?

开发者 https://www.devze.com 2022-12-11 07:34 出处:网络
There are groups like this; USER_ID SEQ_ID NAME 12Armut 13Elma 14Kiraz 21Nar 22Uzum 43Sheftali 44Karpuz 45Kavun

There are groups like this;

USER_ID SEQ_ID NAME
1       2      Armut
1       3      Elma
1       4      Kiraz
2       1      Nar
2       2      Uzum
4       3      Sheftali
4       4      Karpuz
4       5      Kavun

After select query I want to see only;

USER_ID SEQ_ID NAME
1       2      Armut
2       1      Nar
4       3      Karpuz

That is, I want the row with the least SEQ_ID for each USER_ID. What SQ开发者_如何转开发L query will give me this result?

Best regards


SELECT USER_ID, SEQ_ID, NAME 
  FROM table
  WHERE NAME IN ('Armut', 'Nar', 'Karpuz')
  ORDER BY USER_ID

If you have something else in mind, please clarify your question.


Looks to me like it should be:

SELECT USER_ID, MIN(SEQ_ID) AS SEQ_ID, NAME
FROM table
GROUP BY USER_ID, NAME
ORDER BY USER_ID;
0

精彩评论

暂无评论...
验证码 换一张
取 消