Review the joins presented in the previous videos, and get some hands-on practice.
You might be thinking, “What on earth is a Cross Join?” We didn’t cover Cross Joins because they are not very common, but they do serve a purpose. And being able to recognize a Cross Join can actually help you if you’re troubleshooting sometimes.
A Cross Join takes each row from the first table and matches it with every row in the second table. This can be useful if you ever need to select all possible combinations of rows from two tables. For instance, if I had two tables with 10 rows each and I cross joined them, I would get a 100 row result set back.
Where this knowledge really comes in handy is if you ever see data that is being duplicated many times over unexpectedly in a query result, you may have done something wrong in your Inner Join that caused the matching criteria to be ignored. It’s a sign to go back and double check that you have the proper equality statement in the ON portion of the Inner Join section.
See all of the SQL used in Querying Relational Databases in the Querying Relational Databases Cheat Sheet.
We've added a couple of very important tools to our SQL tool belt, joins. 0:00 Joins are the most powerful tools at your disposal. 0:04 Let's review. 0:07 A join is a way we instruct a database to combine the data from two or 0:10 more tables in one result set. 0:14 There are different types of joins. 0:17 The two most common are inner join and outer join. 0:19 We have more information on these and 0:22 other types of joins in the teacher's notes. 0:25 Queries with more than one table joined together using inner joins will 0:28 only return matching data in all join tables. 0:33 The join clause always follows from in your query. 0:36 We use the on keyword to tell the database which columns to use during the join 0:39 process. 0:44 Any search, grouping or ordering criteria come after your joint. 0:45 Remember that the order in which you specify your tables for 0:50 outer joins matter. 0:53 The first table listed immediately after the from is considered the left table and 0:55 is the one that will return all the rows even if it doesn't match 1:00 in the other table. 1:05 Only matching rows will be returned from the table on the right. 1:06 An outer join is written like an inner join. 1:11 The join clause comes after the from clause. 1:14 Launches a SQL playground with this video because it's now time for 1:18 you to practice what you've learned about inner and outer joins. 1:21 You'll be required to lean on all your SQL experience that you've learned here at 1:25 Treehouse. 1:29 Familiarize yourself with the database schema for this small library. 1:30 There's a books table containing all books that the library has to offer. 1:34 There's a loans table containing a ledger of all book loans. 1:39 Finally, there's a patrons table containing all users of our library. 1:43 In the coding sections at the top left, I've presented SQL challenges for 1:47 you to tackle. 1:51 For example, in this coding section, 1:53 I've asked you to select all library patrons with outstanding books. 1:55 Good luck and I'll see you in the next stage. 2:00
You need to sign up for Treehouse in order to download course files.Sign up