Last active
January 22, 2016 09:58
-
-
Save fcaldarelli/1ee7ea87064a7b6cdf80 to your computer and use it in GitHub Desktop.
Order database results with specific field values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Specific order clause | |
-- In PostgreSQL can be used CASE ... WHEN in order clause: | |
ORDER BY | |
CASE field_to_order | |
WHEN 'value1' THEN 1 | |
WHEN 'value2' THEN 2 | |
WHEN 'value3' THEN 3 | |
ELSE 4 | |
END, | |
other_field_to_order | |
-- In MySQL can be used also FIELD() function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment