Last active
July 28, 2016 07:41
-
-
Save tasdemirbahadir/e96a494075579f0631f31ead0a9e7bb7 to your computer and use it in GitHub Desktop.
Check if records have any record inside a one-to-many relation table or not
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 | |
t.field1, | |
t.field2, | |
contains.id is not null contains_record | |
FROM | |
table t | |
LEFT JOIN | |
(select tom.* from table_one_to_many_relation tom where tom.id = 1) contains on contains.table_id = t.id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This query is a design pattern to fetch records with the information if they contain an item from a one-to-many or many-to-many relation table