r/webdev • • Mar 22 '19

SQL joins

/img/xd0kgoexwon21.jpg
2.7k Upvotes

118 comments sorted by

View all comments

Show parent comment

4

u/wxtrails Mar 22 '19

I've been writing SQL for 13 years, and those + unions and subselects cover 100% of the queries I've ever written outside a class or tutorial. And window functions....mmmmm, yes.

What's an outer join again?

3

u/sumguy720 Mar 23 '19

select * from reddit_users outer join reddit_posts using (reddit_username)

would return a list of all reddit users with no posts (with nulls for their post data) and all reddit posts that somehow don't correspond to a user (with nulls for their user data). The final result would be a bunch of rows with blank data on the left, and a bunch of rows with blank data on the right.

Handy if you need to remove the overlap of two lists of items.