MySQL rownum

If you want an incremented row number returned from your query, based on the number of rows, it’s easy in Oracle, I know, but its not too hard in MySQL either.

– Initialise your rownum variable as @rownum
– set it to be @rownum+1
– get it from a dummy table, and set @rownum to initially be 0


SELECT @rownum:=@rownum+1 AS rownum, t.yourField 
FROM   yourTable t, (SELECT @rownum:=0) r 
WHERE  X = X
etc..