Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## A tricky left join
- Consider the following two queries, one that uses an inner join and one that uses a left join
- ```sql
- -- A. Inner join with a where condition
- select foo.*, bar.*
- from foo
- join bar
- on foo.x = bar.x
- where bar.y = 'my_favorite_y'
- -- B. Left join with a where condition
- select foo.*, bar.*
- from foo
- left join bar
- on foo.x = bar.x
- where bar.y = 'my_favorite_y'
- ```
- It turns out that even though query B uses a left join, the two queries will return the same results!
- ## WAT
- (TODO)
- ## The solution
- ```sql
- select foo.*, bar.*
- from foo
- left join bar
- on (foo.x = bar.x and bar.y = 'my_favorite_y')
- ```
- (TODO)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement