Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numbering the records 2

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,548
US

If I have some simple SQL like:
Code:
Select FName, LName, Office from MyTable Where Office = 'Mgmt'
and I get the records:
[tt]
FName LName Office
Bob Brown Mgmt
Susie Smith Mgmt
Joe Horse Mgmt[/tt]

How would my Select look like if I want to add a column to number the records:

[tt]
Line_No FName LName Office
1 Bob Brown Mgmt
2 Susie Smith Mgmt
3 Joe Horse Mgmt[/tt]

???

Have fun.

---- Andy
 
Code:
Select rownum,FName, LName, Office from MyTable Where Office = 'Mgmt'

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
Sorry, you wanted the column to have the name "Line_no", so the code would read:
Code:
Select rownum line_no,FName, LName, Office from MyTable Where Office = 'Mgmt'

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
and if you wanted to order them

Code:
Select rownum line_no,FName, LName, Office
from
(select FName, LName, Office 
 from MyTable 
 Where Office = 'Mgmt' 
 order by Office,LName,FName)


Bill
Lead Application Developer
New York State, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top