If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > row count column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-16-04, 13:32
PDK PDK is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
row count column

I am doing an sql query against multiple linked tables.

Output is:

Field1 Field2 Field3
aaa bbb ccc
bbb ddd sss
ccc rrrr 555

want it to look like:

Counter Field1 Field2 Field3
1 aaa bbb ccc
2 bbb ddd sss
3 ccc rrrr 555

Basicly looking for column one to have which row number is in the results, however many rows there are.

Kind of like an autonumber in Access.

Sounds simple, but having trouble figuring out this one!

Any help would be appreciated.

Thanks,
Reply With Quote
  #2 (permalink)  
Old 04-16-04, 14:04
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
This is easy to do on the client. It is hard (and mostly meaningless) to do using SQL.

The simplest way to do on the server side it is to create a temporary table with a count column. After you've built all of the rows into the temp table, create a cursor and number the rows. Keep in mind that you are going to a lot of extra work that is meaningless in a relational context... This is purely a crutch to make identifying rows even easier that is already very easy on the client, but it means nothing to the server.

I'd very strongly suggest doing the numbering on the client side.

-PatP
Reply With Quote
  #3 (permalink)  
Old 04-16-04, 14:20
PDK PDK is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
Server side

Really need it as part of the select statement, if possible.

Anybody??

Thanks,
Reply With Quote
  #4 (permalink)  
Old 04-16-04, 14:39
pinakdb pinakdb is offline
Registered User
 
Join Date: Feb 2004
Posts: 108
Include ROWNUM in the select statement.

BTW, any drawbacks ?
Order by clause will disturb your rownums.
Reply With Quote
  #5 (permalink)  
Old 04-16-04, 14:40
pinakdb pinakdb is offline
Registered User
 
Join Date: Feb 2004
Posts: 108
Quote:
Originally posted by pinakdb
Include ROWNUM in the select statement.

BTW, any drawbacks ?
Order by clause will disturb your rownums.
Oops .... it's access ! That was only for oracle.
Sorry !
Reply With Quote
  #6 (permalink)  
Old 04-16-04, 14:52
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Re: Server side

Quote:
Originally posted by PDK
Really need it as part of the select statement, if possible.
We all have to deal with ILCs sometimes. What database engine are you using?

-PatP
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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On