开始使用免费开始使用

INNER JOIN(III)——连接 3 个表

我们已经学习了如何连接 2 个表——albumtrack,以及 albumartist。在本练习中,您将把这三个表都连接起来,以获得更完整的结果集。您将继续使用 INNER JOIN,但需要指定不止一次。

请注意,由于 trackartist 都包含 name 列,您需要通过在列名前添加相应的表名前缀来限定(qualify)所选择的列。

本练习是课程的一部分

SQL Server 入门

查看课程

练习说明

  • 在两处都为 name 列添加正确的表前缀以进行限定。
  • 完成两个 INNER JOIN 子句,以连接 albumtrack,以及 artistalbum

交互式实操练习

通过完成这段示例代码来试试这个练习。

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.___;
编辑并运行代码