Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Order by Subquery

Author  Topic 

Phibian
Starting Member

32 Posts

Posted - 2002-05-21 : 18:08:19
Okay, I have a subquery that returns a value by which I'd like to sort.

Eg.
SELECT
X
(SELECT X FROM Table1 WHERE Condition set 1) AS Y,
FROM
Table2
WHERE Condition set 2

I've tried all kinds of things, but I can't order by Y. I'm obviously missing something.

Thanks

jbkayne
Posting Yak Master

100 Posts

Posted - 2002-05-21 : 18:31:26
I wrote an example that may help you...

I assume you want a correlated subquery since a regular subquery would not vary from row to row (wouldn't make sense for sorting).

use pubs

select title
, (select pub_name from publishers where pub_id = titles.pub_id) as pub_name
from titles
order by pub_name

Go to Top of Page
   

- Advertisement -