INNER JOIN(III)——连接 3 个表
我们已经学习了如何连接 2 个表——album 与 track,以及 album 与 artist。在本练习中,您将把这三个表都连接起来,以获得更完整的结果集。您将继续使用 INNER JOIN,但需要指定不止一次。
请注意,由于 track 和 artist 都包含 name 列,您需要通过在列名前添加相应的表名前缀来限定(qualify)所选择的列。
本练习是课程的一部分
SQL Server 入门
练习说明
- 在两处都为
name列添加正确的表前缀以进行限定。 - 完成两个
INNER JOIN子句,以连接album与track,以及artist与album。
交互式实操练习
通过完成这段示例代码来试试这个练习。
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.___;