Tuesday, February 24, 2009

How to Number Rows in MySQL

I was looking for a way to number the row in a sql select result. A search lead me to the following.
How to number rows in MySQL at Xaprb
set @type = ''; set @num = 1; select type, variety, @num := if(@type = type, @num + 1, 1) as row_number, @type := type as dummy from fruits;

1 comment:

  1. Thank you so much it was a fantastic help, now to number rows in mysql is definitely easy with the help of your recommendation. Thanks