note: will work only if each term in the $IDS list is the same length, and if there is a fixed number of them – otherwise, you’ll have to consider designing a new “sequence” table containing the $IDS terms each in its own row, along with a sequence number
okay, so whatever language you are using to generate the query and insert the $IDS string, you will have to use that language to generate the CASE expressions
Can you give me an example of the case statement, may be you can take the my example query and give me an idea like what the case statement should look like ?
SELECT id
, name
, some_date
FROM mytable
WHERE name IN ( 'Curly'
, 'Larry'
, 'Moe'
, 'Shemp'
, 'Joe'
, 'Curly Joe' )
ORDER
BY CASE WHEN name = 'Curly' THEN 1
WHEN name = 'Larry' THEN 2
WHEN name = 'Moe' THEN 3
WHEN name = 'Shemp' THEN 4
WHEN name = 'Joe' THEN 5
WHEN name = 'Curly Joe' THEN 6
ELSE 9 END
, some_date DESC