Created
September 18, 2012 18:12
-
-
Save larste/3744758 to your computer and use it in GitHub Desktop.
Join multiple tables with different columns
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 i.*, | |
n.title, | |
n.url, | |
'NULL' as description | |
FROM items i JOIN news n ON n.item_id = i.id | |
UNION ALL | |
SELECT i.*, | |
j.title, | |
j.url, | |
'NULL' as description | |
FROM items i JOIN jobs j ON j.item_id = i.id | |
UNION ALL | |
SELECT i.*, | |
'NULL' AS title, | |
'NULL' AS url, q.description | |
FROM items i JOIN questions q ON q.item_id = i.id | |
ORDER BY created_at DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment