Mysql – make each row increment by 1


I want to make a sql query and I want each row to have a column indicating the row number ex:

linha     nome
1          joao
2          maria
3          tiago
.          .
.          .
.          .
n          joares

But, this column "row" I don't have in the table, so I'm trying to do something like:

select count(nome), nome from pessoas;

The problem is that when I use count ()


To avoid the declaration you can use the variable as a table:

    @num := @num + 1,
from tab_usuario u, (SELECT @num := 0) as t
group by u.usu_id;
Scroll to Top