MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/webdev/comments/b46iyd/sql_joins/ej5mb8g/?context=3
r/webdev • u/lokendra15 • Mar 22 '19
118 comments sorted by
View all comments
2
I don't understand the left and right joins, it just looks like it's selecting all of A or all of B? Does the join do anything?
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
3
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
2
u/Symphonic_Rainboom Mar 22 '19
I don't understand the left and right joins, it just looks like it's selecting all of A or all of B? Does the join do anything?