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

Set ORDER BY order

Status
Not open for further replies.

SPYDERIX

Technical User
Joined
Jan 11, 2002
Messages
1,899
Location
CA
Hi,

I have a weird question regarding double order by statements in sql and pre-loaing a user defined order.

Assume the following entries in mysql:
Code:
id     make      age
--     ----      ---
1      alpha     new
2      alpha     old
3      charlie   old
4      delta     new
5      beta      old
6      charlie   new

I want to do a double "order by" statement in mysql to go by 2 columns ie - show make in order but within that always show the order of age as well. This is easy enough to do and I already know the syntax - ORDER BY make,age

That will output the following:

Code:
1      alpha     new
2      alpha     old
5      beta      old
6      charlie   new
3      charlie   old
4      delta     new

BUT

My question is this:

Within ORDER BY make,age can you pre-set a user defined order so that `beta` will always return first before the rest does alphabetically.

Can you do anything like ORDER BY make('beta'),age so that it would output this:

Code:
5      beta      old
1      alpha     new
2      alpha     old
6      charlie   new
3      charlie   old
4      delta     new

I know I could do 2 sql queries and append the 2nd returned array onto the 1st returned array but I would rather not have to do that if possible. Is there any way to do this with one sql statement and 1 query?

Thanks alot!

NATE


mainframe.gif


Got a question? Search G O O G L E for links to the fastest answers: www.google.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top