Here is my MySQL query:
SELECT name FROM table;
How can I also select an increment counter alongside name? Expected output:
name
SELECT name, @rownum := @rownum + 1 as row_number FROM your_table , (select @rownum := 0) r
I prefer using a comma instead of CROSS JOIN as it performs faster. Using CROSS JOIN will add one extra step of adding a column to your table.
CROSS JOIN