Enter your email address:

    Delivered by FeedBurner

Monday, February 23, 2009

SQL: Sequence Number on a Select Query

If you need to put a sequence number on the records from your SELECT query, you can do the following technique.

select @n := 0;
select @n:=@n+1 as rec, contactname from contact;


The first statement initializes the variable "n". The second statement uses the variable on the first statement.

A sample output record from the select statement is as follows:







reccontactname
1Marilou
2Ivan
3Harris
4Nelson
5Peter

0 comments:

Post a Comment

About Me

My photo
I provide health supplements, adult wellness products, glutathione, and other merchandise. Please visit my online shop at: http://luckycowshop.blogspot.com/