i want to use an order by clause. my issue is that the values i have are alpha and i need the top of the order to be 'A', 'S', then what ever. how can i sort this column and have the top two being 'A's and 'S's??
thanks in advance
eThere are several ways. Perhaps the laziest is to select a field only for ordering purposes.
SELECT lastname, toto, tata
CASE WHEN lastname LIKE ('A%') THEN 1
WHEN lastname LIKE('S%') THEN 2
ELSE 3
END as Ord
ORDER by ord, lastname
Another is to use several queries and the UNION operator
SELECT .. FROM ..
WHERE
lastname like ('A%')
ORDER BY lastname
UNION
...
where lastname like ('S%')
ORDER BY lastname
UNION
WHER lastname not like ('A%') and lastname not like ('S%')
ORDER BY lastname|||i think i can make that work... thanks :)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment