Created
September 26, 2011 16:26
-
-
Save douglasmiranda/1242653 to your computer and use it in GitHub Desktop.
SQL ORDER BY ignoring fields filled with "0"
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
-- This problem happens when you try to order columns ASC | |
-- and you want to ignore the 0 values in the first results | |
SELECT `DATABASE_NAME`.* | |
FROM `TABLE_NAME` | |
ORDER BY | |
CASE WHEN `FIELD_FILL_WITH_0` in("", "0") THEN 1 | |
ELSE 0 END, `FIELD_FILL_WITH_0_OR_ANY_OTHER_FIELD` ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment