Click to See Complete Forum and Search --> : Order By


callumd
06-19-2007, 12:45 AM
Hi all,

I have a SELECT query that is along the lines of:

SELECT tvshow, tvchannel FROM tvshows WHERE tvshow IN ('Happy Days', 'The Simpsons', 'Family Guy', 'Futurama');

What I would like to do is ORDER these results in the order that they appear in the IN clause.

Can this be done in a query? Or will I have to resort to using a server-side script?

bubbisthedog
06-20-2007, 08:48 AM
One method could be to use UNION ALL.
SELECT tvshow, tvchannel FROM tvshows WHERE tvshow = 'Happy Days'
UNION ALL
SELECT tvshow, tvchannel FROM tvshows WHERE tvshow = 'The Simpsons'
UNION ALL
SELECT tvshow, tvchannel FROM tvshows WHERE tvshow = 'Family Guy'
UNION ALL
SELECT tvshow, tvchannel FROM tvshows WHERE tvshow = 'Futurama';