Forum Moderators: open

Message Too Old, No Replies

MySQL Query: Display one then order others

MySQL query to display one record from a table then sort the others

         

anawaz

9:08 am on Sep 11, 2009 (gmt 0)

10+ Year Member



Hi folks,

I'm trying to write a query where I basically want to get the information out of a table and order it by one of the fields, but I want to do this after choosing ONE to display first.

So, essentially, in english SQL pseudo this would be something like:


SELECT name, description
FROM table
WHERE id=$Variable
ORDER BY name ASC But
Please display name22 first.

I have the ID and name of the item I want to display first. This is a simplified version of the issue I have. Usually I would do one query with the ID that I have and the other without the ID to get all the results, but this is all part of a dynamic menu, so I just want to be able to do it in the query.

Is this possible and if so how?

LifeinAsia

3:37 pm on Sep 11, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Maybe something like:
SELECT name, description, 1 AS SortOrder
FROM table
WHERE id=$Variable AND name='name22'
UNION
SELECT name, description, 2 AS SortOrder
FROM table
WHERE id=$Variable AND name<>'name22'
ORDER BY SortOrder, name