Add row_number() in MySQL
12 September 2010
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:
(For php using mysql_query, the above should be put into 2 mysql_query functions)