Answer the question
In order to leave comments, you need to log in
Is it possible to get the first order from a group?
For example, there is a table with an auto-increment id and a group_key column. And let's say in the table 2 records have group_key equal to 4 and 3 records have group_key equal to 44, and I need to get the first 2 of this group, like
id = 1, group_key = 4
id = 32, group_key = 44
Answer the question
In order to leave comments, you need to log in
SELECT min(id), group_key
FROM table_name
GROUP BY group_key
where table_name is the name of the table in the database
SELECT MIN(id), group_key FROM your_table GROUP BY group_key
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question