Web Development Blog

24K Design Studio :: Blog :: Add row_number() in MySQL
Author:
Password:
Add row_number() in MySQL
06:13, 14 Sep, 2010
by David

In MSSQL, we have row_number, and in MySQL, we have limit

Sometimes, the task is to find the record before and after a certain record. When the ordering is complex, it seems not easy for MySQL to do this, so row_number can be useful here.

But MySQL does not support row_number (when this entry is written at MySQL 5.1.50)
Here is one widely used solution:
set @row_number=0;select(@row_number:=@row_number+1)as`row_number`from...
(For php using mysql_query, the above should be put into 2 mysql_query functions)

Reference:http://blog.chinaunix.net/u3/93470/showart_1931377.html

Reply:
Your name:
Only visible to the author.

Tell us you are not a robot. What is captcha1captchaOcaptcha2 = 

Reply
View the latest 5 entries.