|
Posted by Bill Karwin on September 4, 2006, 4:45 pm
Please log in for more thread options
furqonk@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.
|