MySQL: Numbering query output lines

This entry is part 23 of 26 in the series Learn MySQL

Sometimes you might like the lines of a query result nicely numbered.

This can be doned by using a user defined variable.

Expressions involving variables are evaluated for each row of a query result, a property that you can use to provide a column of row numbers in the output.

set @n = 0;
select @n := @n + 1 as row, artiste, album, price from artist;



Series Navigation<< MySQL: Setting a select result to a variable
MySQL: Mathematical expression >>

Leave a comment

Leave a Reply