views:

42

answers:

1

Hey all,

I'm trying to write an SQL query that would populate a dropdown box of locations. In addition, I need the query to select the location associated with a user automatically (ie: be the first in the list results.) I had the following, but recently realized that the list isn't completely alphabetized. To add another level to this, presume that I only have SELECT access to this database.

select  
    [LOCATION] 
from User_Table
where [ALIAS] = 'UserName' 
UNION all 

select 
    distinct [LOCATION]
from Location_Table 
where [STATUS_VALUE] ='Open'

If I "order by 1", then the location associated with the user is shuffled in with others and not the first item on the list.

Any help would be awesome.

EDIT: Maybe this will help to make it clearer. The larger list of locations seem to be built quasi-alphabetically based on their indexes. So halfway through the list, I get results like this:

WOODBRIDGE YOKOTA/JAPAN ABERDEEN PROVING GROUND ALBUQUERQUE

+1  A: 
SELECT [LOCATION]
FROM 
(
select  
    [LOCATION], 1 AS [Sort]
from User_Table
where [ALIAS] = 'UserName' 
UNION all 

select 
    distinct [LOCATION], 0 AS [Sort]
from Location_Table 
where [STATUS_VALUE] ='Open'
) Locations
ORDER BY [Sort]
rdkleine
Sort values are backwards for Users Location to appear first.
Gordon Bell
Interestingly, that produces the same results as my query, except the current location is at the bottom. Adding "desc", to it provides the exact same results. Thanks!
JcksnPS4
Almost, close enough :) Can you mark this as answered?
rdkleine