Friday, January 25, 2019

How to order alphabetically EXCEPT for one item?

SELECT name,CreatedOn
FROM categories
ORDER BY name ASC, CreatedOn DESC

an explicit CASE expression, which is standard SQL and will work in any database system, is better --

ORDER
    BY CASE WHEN name = 'Other'
            THEN 1 -- last
            ELSE 0 -- first
        END ASC
     , CreatedOn DESC

No comments:

Post a Comment