r/webdev • • Mar 22 '19

SQL joins

/img/xd0kgoexwon21.jpg
2.7k Upvotes

118 comments sorted by

View all comments

Show parent comment

3

u/rglitched Mar 22 '19

Left joins will include all the data from the first table and show you the matching data from the second table where it exists.

Right join is the same idea from the other direction. Hopefully this helps?

Table A contains:
1
2
3
4
5

Table B contains:

3
5
7
9
11

JOIN (inner join) returns:
3-3
5-5

LEFT JOIN returns
1 - NULL
2 - NULL
3 - 3
4 - NULL
5 - 5

RIGHT JOIN returns

3 - 3
5 - 5
NULL - 7
NULL - 9
NULL - 11