Created
May 13, 2011 14:24
-
-
Save davejlong/970617 to your computer and use it in GitHub Desktop.
SQL Output with Nulls at the bottom of the output
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
SELECT schools.id AS schoolid,schools.name AS school,districts.id AS districtid, districts.name AS district | |
FROM sms_schools AS schools | |
LEFT JOIN sms_districts AS districts ON schools.districtid = districts.id | |
WHERE 1 = 1 | |
ORDER BY (CASE WHEN districts.id IS NULL then 1 ELSE 0 END),districts.name, schools.name; |
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
SELECT | |
schools.id AS schoolid, | |
schools.name AS school, | |
districts.id AS districtid, | |
(CASE WHEN districts.name IS NULL THEN 'Other' ELSE districts.name END) AS district | |
FROM sms_schools AS schools | |
LEFT JOIN sms_districts AS districts ON schools.districtid = districts.id | |
WHERE 1 = 1 | |
ORDER BY (CASE WHEN districts.id IS NULL then 1 ELSE 0 END),districts.name, schools.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment