Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL a numbering column - MySQL

Tags:

sql

mysql

This is a sql newbie question.

Basically, I want an extra column to return with my select statement to number the rows. I'm using mysql.

Eg:

select * from friends

David
Steve
Joe

What is the syntax to get:

1  David
2  Steve
3  Joe
like image 560
Yada Avatar asked Dec 22 '08 02:12

Yada


1 Answers

From: http://markmal.blogspot.com/2006/04/oracle-like-rownum-in-mysql.html

SELECT @rownum:=@rownum+1 rownum, t.*FROM (SELECT @rownum:=0) r, mytable t;
like image 127
Paul Tomblin Avatar answered Sep 29 '22 10:09

Paul Tomblin