Last active
August 6, 2018 22:15
-
-
Save srhyne/8e3207ca1ce3b92d94aed168dded9869 to your computer and use it in GitHub Desktop.
Normalize polymorphic foreign relationships using union all
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
-- using union all to normalize | |
select id, name, foo, bar from ( | |
select * from messages | |
left join broadcasts on broadcasts.id = messages.type_id | |
where type = 'broadcast' | |
union | |
select * from messages | |
left join auto_followups on auto_followups.id = messages.type_id | |
where type = 'auto-follow-up' | |
) t; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment