Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
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.
Joins are the most powerful tools at your disposal.
A join is a way we instruct a database to combine the data from two or
more tables in one result set.
There are different types of joins.
The two most common are inner join and outer join.
We have more information on these and
other types of joins in the teacher's notes.
Queries with more than one table joined together using inner joins will
only return matching data in all join tables.
The join clause always follows from in your query.
We use the on keyword to tell the database which columns to use during the join
Any search, grouping or ordering criteria come after your joint.
Remember that the order in which you specify your tables for
outer joins matter.
The first table listed immediately after the from is considered the left table and
is the one that will return all the rows even if it doesn't match
in the other table.
Only matching rows will be returned from the table on the right.
An outer join is written like an inner join.
The join clause comes after the from clause.
Launches a SQL playground with this video because it's now time for
you to practice what you've learned about inner and outer joins.
You'll be required to lean on all your SQL experience that you've learned here at
Familiarize yourself with the database schema for this small library.
There's a books table containing all books that the library has to offer.
There's a loans table containing a ledger of all book loans.
Finally, there's a patrons table containing all users of our library.
In the coding sections at the top left, I've presented SQL challenges for
you to tackle.
For example, in this coding section,
I've asked you to select all library patrons with outstanding books.
Good luck and I'll see you in the next stage.
You need to sign up for Treehouse in order to download course files.Sign up