Answer the question
In order to leave comments, you need to log in
How to group by two fields and select the maximum group from them?
i have a table with such fields
they need to be grouped what i do :
SELECT id_new,id_user
FROM tbl_bookmarks
GROUP BY id_user,id_new i
get this result
after which you need to select the maximum group, that is, the result should be
5 - 1
4 - 3
2 - 4
3 - 4
1 - 5
I hope it's possible)
Answer the question
In order to leave comments, you need to log in
It is possible using RANK.
SELECT
id_new,
id_user
FROM (
SELECT
id_new,
id_user,
RANK() OVER (PARTITION BY id_user ORDER by id_new DESK ) AS RNK
FROM tbl_bookmarks
GROUP BY id_user,id_new
) X WHERE RNK=1
SELECT MAX(id_new),id_user
FROM tbl_bookmarks
GROUP BY id_user
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question