I am trying to write an sql query for Microsoft SQL Server 2008. Here is a quick sample of my query.
SELECT DISTINCT(field1)
FROM myDatabase
WHERE field1 IN ('dynamic list of ids')
OR ....lots of other conditions....
I then want to order by those ids in the dynamic list descending and then the rest descending. Something to this effect.
ORDER BY field1 IN ('dynamic list of ids') DESC,
field1 DESC
How am i able to have the ids in the dynamic list first?
Thanks
EDIT – Added DISTINCT to query.
EDIT – Answer as provided by Shan Plourde.
SELECT DISTINCT(field1),
CASE
WHEN field1 IN ('dynamic list of ids') THEN 1
ELSE 0
END AS logicalOrderingColumn
FROM myDatabase
WHERE field1 IN ('dynamic list of ids')
OR ....lots of other conditions....
ORDER BY logicalOrderingColumn DESC, field1 DESC
something like this?