Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMatt Nickolls
9,895 PointsNot sure about the distinction between Join and outer join
Hi all
Would someone be able to explain in more detail what the distinction is between 'join' and 'left outer join'. Alena mentions that outer join should be used when you only want to select and retrieve an item that exists....but I'm not sure how you would select an item at all if it didn't exist in the first place? Could someone help me visualise this?
Also what is the purpose of specifying a 'left' relative position for 'left outer join' when there is no such position specified for 'join' when joining the media and genre table? Alena mentions that this is because the media table is to the left of the books table, and we want to pull data from left to right direction. Why did the genre table join not need a relative position to be specified?
Thank very much as always guys.
Matt :)
2 Answers
Peter Vann
36,427 PointsHere are the different types of JOINs in SQL:
(INNER) JOIN: Returns records that have matching values in both tables LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records from the right table RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched records from the left table FULL (OUTER) JOIN: Returns all records when there is a match in either the left or right table
For more info (and the source of the above text): https://www.w3schools.com/sql/sql_join.asp
Example syntax:
SELECT *
FROM Orders As o
LEFT JOIN Customers As c
ON o.CustomerID = c.CustomerID;
And more: https://www.sql-join.com/
I hope that helps. Happy coding!
Matt Nickolls
9,895 PointsThanks Peter, yes that is very helpful.
Peter Vann
36,427 PointsPeter Vann
36,427 PointsMore resources: https://www.youtube.com/results?search_query=SQL+Joins https://www.youtube.com/watch?v=XqIk2PwP0To