Jointure interne (III) - Jointure de 3 tableaux
Nous avons vu comment joindre deux tableaux - album
avec track
, et album
avec artist
. Dans cet exercice, vous joindrez les trois tableaux pour obtenir un ensemble de résultats plus complet. Vous continuerez à utiliser INNER JOIN
, mais vous devrez en spécifier plusieurs.
Notez ici que, comme track
et artist
contiennent tous deux une colonne name
, vous devez qualify
sélectionner les colonnes en faisant précéder le nom de la colonne du nom du tableau concerné.
Cet exercice fait partie du cours
Introduction au serveur SQL
Instructions
- Qualifiez la colonne
name
en spécifiant le préfixe de tableau correct dans les deux cas. - Complétez les deux clauses de
INNER JOIN
pour joindrealbum
àtrack
, etartist
àalbum
.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
SELECT track_id,
-- Enter the correct table name prefix when retrieving the name column from the track table
___.name AS track_name,
title as album_title,
-- Enter the correct table name prefix when retrieving the name column from the artist table
___.name AS artist_name
FROM track
-- Complete the matching columns to join album with track, and artist with album
INNER JOIN album on track.___ = album.album_id
INNER JOIN artist on album.artist_id = artist.___;