Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Understanding Relationship Tables 3:41
- Relational Data 5 questions
- Querying Multiple Tables with JOIN 4:02
- JOINing Tables 1 objective
- Understanding SQL Injections 5:21
- SQL Injection 1 question
- Preparing SQL Statements 6:25
- Using a Prepared Statement 3 objectives
- Adding a Secondary Query 4:30
- Fetching in a While Loop 7:38
- Fetching Many Relationships 1 objective

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
JOIN is a method for combining, or joining, together data from multiple tables. We’ll use JOIN to add the extra details we need from our Genre and Books tables. We’ll also explore another fetch method.
Database Diagram
Links
WHAT IS A SQL JOIN?
SQL Basics course
Database Foundations
Example Code
<?php
try {
$results = $db->query(
"SELECT title, category, img, format, year,
publisher, isbn, genre
FROM Media
JOIN Genres ON Media.genre_id=Genres.genre_id
LEFT OUTER JOIN Books
ON Media.media_id = Books.media_id
WHERE Media.media_id = ?"
);
} catch (Exception $e) {
echo "bad query";
echo $e;
}
$item = $results->fetch(PDO::FETCH_ASSOC);
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Samir Poonawala
29,951 Points1 Answer
-
Matt Nickolls
9,895 Points1 Answer
-
Matt Nickolls
9,895 Points2 Answers
-
Thomas Hewitt
17,691 Points1 Answer
-
Riki Tiilikainen
4,042 Points2 Answers
-
Siraj Khan
3,451 PointsI couldn't get my head around anything the instructor saying over here.!
Posted by Siraj KhanSiraj Khan
3,451 Points2 Answers
-
Sean Flanagan
33,236 Points4 Answers
-
Robbie Thomas
31,093 Points1 Answer
-
jlampstack
23,932 Points0 Answers
-
Alex Forseth
8,017 PointsIs the database diagram what Alena is referencing when she says "that it is on the left"?
Posted by Alex ForsethAlex Forseth
8,017 Points1 Answer
-
Andrew Dickens
18,352 Points2 Answers
-
Artan Muzhaqi
7,983 PointsThe code doesn't work. Unable to retrieve results SQLSTATE[HY000]: General error: 1 ambiguous column name: media_id
Posted by Artan MuzhaqiArtan Muzhaqi
7,983 Points1 Answer
-
Mark Miller
45,831 PointsWhy not fetchAll() when the query is specifically returning what we need?
Posted by Mark MillerMark Miller
45,831 Points2 Answers
-
jlampstack
23,932 Points3 Answers
-
Attila Balog
5,217 PointsI'm disappointed, bad code from the beginning of this course
Posted by Attila BalogAttila Balog
5,217 Points3 Answers
-
Ronaldo Fialho
5,105 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
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