MySQL Forums
Forum List  »  Newbie

Re: can we use as like as rownum in mysql or not????/
Posted by: Andrew Gilfrin
Date: July 18, 2005 08:53AM

To get the first N rows you just use limit. Apart from the syntax it works just the same as rownum in Oracle. If you need it in the select statement try something like this.

mysql> set @rownum = 0;
-> //
Query OK, 0 rows affected (0.00 sec)

mysql> select @rownum := @rownum + 1 as rownum, emp_name from emps;
-> //
+--------+----------+
| rownum | emp_name |
+--------+----------+
| 1 | Roger |
| 2 | John |
| 3 | Alan |
+--------+----------+
3 rows in set (0.00 sec)

Andrew Gilfrin
------------------
http://gilfster.blogspot.com
My MySQL related Blog

http://www.mysqldevelopment.com
MySQL Stored Procedure,Trigger, View.... (Just about most things these days) Information

Options: ReplyQuote


Subject
Written By
Posted
Re: can we use as like as rownum in mysql or not????/
July 18, 2005 08:53AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.