9 messages in com.mysql.lists.mysqlRE: mysql top 2 rows for each group
FromSent OnAttachments
Vivian Wang28 Apr 2005 13:17 
Jay Blanchard28 Apr 2005 13:24 
mathias fatene28 Apr 2005 13:51 
SGr...@unimin.com28 Apr 2005 13:51 
mathias fatene28 Apr 2005 14:32 
Vivian Wang29 Apr 2005 06:28 
mfat...@free.fr29 Apr 2005 06:31 
Vivian Wang29 Apr 2005 06:54 
SGr...@unimin.com29 Apr 2005 07:08 
Subject:RE: mysql top 2 rows for each group
From:Jay Blanchard (jay.@niicommunications.com)
Date:04/28/2005 01:24:01 PM
List:com.mysql.lists.mysql

[snip] I have question about how I can get top 2 rows for each group. like I have table test | seqno | +-----------+ | 000000122 | | 000000123 | | 000000123 | | 000000123 | | 000000336 | | 000000346 | | 000000349 | | 000000427 | | 000000427 | | 000000427 | +-----------+------+

I like have +-----------+------+ | seqno | item | +-----------+------+ | 000000122 | 1 | | 000000123 | 1 | | 000000123 | 2 | | 000000123 | 3 | | 000000336 | 1 | | 000000346 | 1 | | 000000349 | 1 | | 000000427 | 1 | | 000000427 | 2 | | 000000427 | 3 | +-----------+------+

Then I can have select * from test where item <3 to find all top 2 rows. [/snip]

I think you want ...

SELECT DISTINCT(seqno) FROM test ORDER BY seqno LIMIT 2