Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
A join is the instruction to the query engine on how to relate records in one table to records in another.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Previously, we've talked
about database concepts.
0:04
Such as primary keys, foreign keys,
0:07
table relationships,
normalization and set theory.
0:10
These concepts lead the foundation of
how we write more powerful SQL queries.
0:14
We will revisit and
0:20
expand on these topics as we progress
through the rest of this course
0:21
and get more hands on with the data.
0:25
In previous courses,
you've seen lots of examples of queries.
0:28
However, they've all been
from one table at a time.
0:32
But, how can you combine related data for
more than one table?
0:35
You can use something that
is called a table join.
0:40
Using a join in a query tells
the database to mesh the data from
0:43
two different tables together
into one result set.
0:47
The two most common types of joins
are inner join and outer join.
0:51
We're going to learn about
each of these in detail.
0:56
Here we see two tables.
0:59
Customer and customer detail.
1:01
If we want to display the results from
both the tables in the same view,
1:03
we use the keyword JOIN
1:08
to tell SQL to put the data together,
only selecting what we want.
1:10
Let's use a JOIN to select the FirstName
and LastName from the customer table
1:14
and join it to the phone and date of
birth from the customer detail table.
1:19
The result set generated from the query
doesn't affect the original two tables.
1:24
All the data is there,
1:30
separated.
1:31
Only the result set is shown
based on the relationship.
1:32
Joins can be used in one to one, one to
many, and many to many relationships.
1:36
In the next video,
we'll look at the first type of join.
1:42
Inner join.
1:46
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up