Created
July 26, 2023 13:56
-
-
Save mikehins/90ad980df473b0967f5ae6800e23f2a1 to your computer and use it in GitHub Desktop.
This file contains 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
# ORDER BY with nullable columns | |
# In MySQL they will be placed before everything. | |
# But the intention of the application or the UX may need a different sort order. | |
# In these cases the ordering for NULL values can be changed easily. | |
-- Default behaviour: NULL values placed first | |
SELECT * | |
FROM customers ORDERBY country ASC; | |
-- NULL values placed first by rule | |
SELECT * | |
FROM customers | |
ORDER BY country ISNOTNULL, country ASC; | |
-- NULL values placed last by rule | |
SELECT* | |
FROM customers | |
ORDER BY country ISNULL, country ASC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment