I want to add the row number as a column of the result set

This is a discussion on I want to add the row number as a column of the result set within the MySQL Database forums, part of the Database Forums category; this is for the reporting does someone knows?...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-26-2007
hi and hello
 
Posts: n/a
Default I want to add the row number as a column of the result set

this is for the reporting
does someone knows?

Reply With Quote
  #2 (permalink)  
Old 04-28-2007
strawberry
 
Posts: n/a
Default Re: I want to add the row number as a column of the result set

On Apr 26, 5:27 pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
> On 25 Apr 2007 21:39:39 -0700, hi and hello wrote:
>
> > this is for the reporting
> > does someone knows?

>
> Add an autoincrementing integer column. Use that. They make dandy
> primary keys as well.
>
> --
> 53. If the beautiful princess that I capture says "I'll never marry you!
> Never, do you hear me, NEVER!!!", I will say "Oh well" and kill her.
> --Peter Anspach's list of things to do as an Evil Overlord



You can also do this:

mysql> set @N = 0;
mysql> SELECT @N := @N +1 AS number, * FROM my_table;

Reply With Quote
  #3 (permalink)  
Old 04-28-2007
strawberry
 
Posts: n/a
Default Re: I want to add the row number as a column of the result set

On Apr 28, 2:44 pm, strawberry <zac.ca...@gmail.com> wrote:
> On Apr 26, 5:27 pm, "Peter H. Coffin" <hell...@ninehells.com> wrote:
>
> > On 25 Apr 2007 21:39:39 -0700, hi and hello wrote:

>
> > > this is for the reporting
> > > does someone knows?

>
> > Add an autoincrementing integer column. Use that. They make dandy
> > primary keys as well.

>
> > --
> > 53. If the beautiful princess that I capture says "I'll never marry you!
> > Never, do you hear me, NEVER!!!", I will say "Oh well" and kill her.
> > --Peter Anspach's list of things to do as an Evil Overlord

>
> You can also do this:
>
> mysql> set @N = 0;
> mysql> SELECT @N := @N +1 AS number, * FROM my_table;



Actually, if using ' * ', then it has to come before the counter.
Also, you have to remember to reset N afterwards!

Reply With Quote
  #4 (permalink)  
Old 05-01-2007
ashore
 
Posts: n/a
Default Re: I want to add the row number as a column of the result set

What you're asking for is "an un-natural act" in SQL. The point is
taht an SQL

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0