Created
March 21, 2024 22:45
-
-
Save jonhassall/7729cab6b1b1f2447f8b9c2758bec8f5 to your computer and use it in GitHub Desktop.
SQL sorting - Alpha > Numbers > Symbols
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
SELECT id, title | |
FROM table | |
ORDER BY | |
CASE | |
WHEN title regexp '^[a-zA-Z]+' THEN | |
1 | |
WHEN title regexp '^[0-9]+' THEN | |
2 | |
WHEN title regexp '^[^\w]+' THEN | |
3 | |
WHEN title = '' | |
OR | |
title IS NULL THEN | |
4 | |
ELSE 5 | |
END, | |
title * 1 ASC, | |
title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment