SQL Column Numbering - MySQL

This is a newbie question in sql.

Basically, I want an extra column to be returned with my select statement for the row number. I am using mysql.

For example:

select * from friends

David
Steve
Joe

What is the syntax:

1  David
2  Steve
3  Joe
+5
source share
5 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;
+7
source

In SQL Server 2005 and above, you can use the Row_Number function .

+1
source

- , , . - . Paul .

MySql ROWNUM, Oracle, Row_Number(), MS SQL Server, .

Edit:

, SQL, .

+1

proc

CREATE TABLE #Foo (
        [FooId] [int] IDENTITY(1,1) NOT NULL,
        [Name] varchar(255)
)

SELECT *
FROM Friends
INTO #Foo

SELECT *
FROM #Foo
0

, , . , ROWNUM .

SQL, , ROW_NUMBER() - @YonahW; .

0

All Articles