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:
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:
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:
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
Got a question? Search G O O G L E for links to the fastest answers: www.google.com
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

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