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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to dispaly ascending and descending order in a single SQL query ?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi

Please hlep me how to display one column in ASC and another column in DESC order in a single query ?

Here is what I want....

The actual data is like this....

Name Friend_name
-------------------
raj srinivas
arvind raghu
venkat charan
sekhar dev
sami arjun

I want the output like this....

Name Friend_name
-------------------
arvind srinivas
raj raghu
sami dev
sekhar charan
venkat arjun


Thanks
Suja
 
Here's how you do it.


SELECT A.name, B.friend_name
FROM (select name, Id = (select Count(name) from Friends where name <= f.name)
FROM friends f) A
JOIN (select friend_name, Id = (select Count(friend_name) from Friends where friend_name >= f.friend_name)
FROM friends f) B on A.Id = B.Id
ORDER BY A.NAME


Andel
andel@barroga.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top