Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Integrating PHP with Databases Using Relational Tables Querying Multiple Tables with JOIN

Not 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

Here 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:

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!

Thanks Peter, yes that is very helpful.