Code snippets and DB28 Apr 2007 07:06 am
I got tired looking for a good solution to imitate a rownum in MySQL every time I need it. Here I post the most
universal solution that doesn’t need a script mode and can be executed in a single statement:
SELECT @rownum:=@rownum+1 rownum, t.*
FROM (SELECT @rownum:=0) r, mytable t;
FROM (SELECT @rownum:=0) r, mytable t;
This solution and others you can find in comments to the MySQL Reference Manual.
