469,890 Members | 1,419 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

How to generate sequence values during query

I have query like below:
SELECT part_no,part_nm,qty FROM tb_stok_out ORDER BY part_no

as result:
part_no part_nm qty

aaa asdfd 3
abab sdfsdf 4
abab adfdf 5

Is it possible in mysql to generate sequence number using query, so the
result will be like below :
1 aaa asdfd 3
2 abab sdfsdf 4
3 abab adfdf 5
... etc

Pls help !!
rgds
Furqon

Sep 4 '06 #1
1 9647
fu*****@gmail.com wrote:
I have query like below:
SELECT part_no,part_nm,qty FROM tb_stok_out ORDER BY part_no

as result:
part_no part_nm qty

aaa asdfd 3
abab sdfsdf 4
abab adfdf 5

Is it possible in mysql to generate sequence number using query, so the
result will be like below :
1 aaa asdfd 3
2 abab sdfsdf 4
3 abab adfdf 5
You can use MySQL's user variables to do something like this:

SET @i = 0;
SELECT @i:=@i+1 AS Monotonically_increasing_value, part_no, part_nm, qty
FROM tb_stock_out ORDER BY part_no;

Note that User variables in MySQL are in the scope of a database
connection. So the value will disappear as soon as your connection
closes (similarly to TEMP tables). If you use MySQL Query Browser, its
default behavior is to open and close a separate connection for each
statement. So don't be surprised if the above solution doesn't work in QB.

Regards,
Bill K.
Sep 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by David Garamond | last post: by
4 posts views Thread by Eric E | last post: by
1 post views Thread by Marek Lewczuk | last post: by
7 posts views Thread by urban.widmark | last post: by
12 posts views Thread by Jim Michaels | last post: by
8 posts views Thread by Marc | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.