How to generate sequence values during query

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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 !!

Re: How to generate sequence values during query wrote:
Quoted text here. Click to load it

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.

Bill K.

Site Timeline