Hi all
Is this at all possible:
Ordering content from a database table in alphabetical order, BUT the first value to be set by myself?
So, for example:
Name Age
Frank 21
Tom 32
Andy 21
Owen 43
So in this example I would want to order that data so that Owen is first, and then we order by alphabetic values, so the outcomes would be
Owen (this is the value I want to appear first)
Andy (then the rest are outputted in alphabetical order)
Frank
Tom
This is just an example, I have alot more data then that and they are not names and ages.
Need help! SQL order by
Moderator: General Moderators
-
newbie2php
- Forum Commoner
- Posts: 35
- Joined: Wed Nov 07, 2007 4:44 pm
Re: Need help! SQL order by
And just to add that this needs to be all in one SQL command
Many thanks
Many thanks
Re: Need help! SQL order by
Remember, SQL is a logical language, not a mind reader. If there is a logical way to determine the order, you can probably express it in SQL, but if the logic is just "I want Owen to appear first", there is no way to do that in one SQL statement. You could write a UNION query that is really two queries, one appended to the other, the first one specifically selecting ONLY the record you want to appear first and the second selecting everything BUT that record, in some order. Your question sounds like a very peculiar situation, indeed. We might be able to help you more if you could explain WHY you would ever want to do this.
Re: Need help! SQL order by
try order by replace(Name,'Owen',NULL)