Sashi Kant Sashi Kant - 5 months ago 25
SQL Question

Is there a way to get the row number in Mysql like the rownum in oracle

Is there a way to get the row number in Mysql like the rownum in oracle, If not then is there any indirect way of doing it?
please suggest.

Answer

Until MySQL finally supports modern SQL, the only way to get something similar is this:

SELECT @rownum:=@rownum + 1 as row_number, 
       t.*
FROM ( 
   < your original query goes here >
) t,
(SELECT @rownum := 0) r