Click here to get back home

How to generate sequence values during query

 HomeNewsGroups | Search | About
 mailing.database.mysql    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
How to generate sequence values during query furqonk 09-04-2006
Get Chitika Premium
Posted by furqonk on September 4, 2006, 4:37 am
Please log in for more thread options
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


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.

Similar ThreadsPosted
Reference to already retrieved values in query March 8, 2006, 1:32 pm
Query that counts multiple values February 9, 2007, 8:31 am
Bulk Insert of new records in sequence October 11, 2005, 7:49 pm
MySQL variables, modifying Microsoft SQL sequence insert for use in mysql October 7, 2005, 10:54 am
Alternate values February 8, 2006, 10:52 pm
Find value not in between values. July 13, 2006, 10:43 am
Update a table with values in another January 18, 2006, 4:51 am
default field values June 15, 2006, 7:39 am
Assigning unique ID to distinct values June 20, 2005, 12:44 pm
Append a string to all the values in a column SQL January 13, 2006, 11:44 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap