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 > sorting but always having specified fields come up first

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-14-06, 17:32
zxcvbs zxcvbs is offline
Registered User
 
Join Date: Oct 2006
Posts: 15
sorting but always having specified fields come up first

is there a way to sort by a field, but have specified fields always appear first?

e.g.:

ID | DATA
1 | ...
2 | ...
3 | ...
4 | ...
8 | ...
10 | ...

I want to retrieve all records ordered by ID ascending, but I want records 8 and 10 to always be first, so the retrieval looks like:

ID | DATA
8 | ...
10 | ...
1 | ...
2 | ...
3 | ...
4 | ...

I know it sounds kind of dumb, but it's kind of the way it is for now. any way to do this without having to use multiple queries?
Reply With Quote
  #2 (permalink)  
Old 11-14-06, 17:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
order
    by case when id in (8,10) then 0 else 937 end
     , id
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 11-15-06, 09:20
zxcvbs zxcvbs is offline
Registered User
 
Join Date: Oct 2006
Posts: 15
worked perfectly. thanks!
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