For your query, just a where clause : mysql> select * from seqs where id <3; +-----------+----+ | seqno | id | +-----------+----+ | 000000122 | 1 | | 000000123 | 1 | | 000000123 | 2 | | 000000336 | 1 | | 000000346 | 1 | | 000000349 | 1 | | 000000427 | 1 | | 000000427 | 2 | +-----------+----+ 8 rows in set (0.00 sec)
Best Regards -------------------- Mathias FATENE Hope that helps *This not an official mysql support answer -----Original Message----- From: mathias fatene [mailto:[EMAIL PROTECTED] Sent: jeudi 28 avril 2005 22:52 To: 'Jay Blanchard'; 'Vivian Wang'; mysql@lists.mysql.com Subject: RE: mysql top 2 rows for each group Hi , The table must be myisam. Innodb refused my solution which is here : ---------------------------------------------------- Beatifull auto_increment mysql> create table seqs(seqno varchar(10) NOT NULL , id int auto_increment, primary key (seqno,id)) engine=myisam; Query OK, 0 rows affected (0.03 sec) mysql> mysql> mysql> insert into seqs(seqno) values('000000122'), -> ('000000123'), -> ('000000123'), -> ('000000123'), -> ('000000336'), -> ('000000346'), -> ('000000349'), -> ('000000427'), -> ('000000427'), -> ('000000427'); Query OK, 10 rows affected (0.00 sec) Records: 10 Duplicates: 0 Warnings: 0 mysql> select * from seqs; +-----------+----+ | seqno | id | +-----------+----+ | 000000122 | 1 | | 000000123 | 1 | | 000000123 | 2 | | 000000123 | 3 | | 000000336 | 1 | | 000000346 | 1 | | 000000349 | 1 | | 000000427 | 1 | | 000000427 | 2 | | 000000427 | 3 | +-----------+----+ 10 rows in set (0.00 sec) ----------------------------------------------------- I like this type of auto_increment Best Regards -------------------- Mathias FATENE Hope that helps *This not an official mysql support answer -----Original Message----- From: Jay Blanchard [mailto:[EMAIL PROTECTED] Sent: jeudi 28 avril 2005 22:24 To: Vivian Wang; mysql@lists.mysql.com Subject: RE: mysql top 2 rows for each group [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 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]