开始使用免费开始使用

RIGHT JOIN

现在来练习一些 RIGHT 连接。RIGHT 连接会返回右表中的所有行,以及与之匹配的左表中的行。

除了执行 RIGHT 连接,您还将学习当不同表具有相同列名时,如何通过在 SELECT 语句中对列进行完全限定来避免问题。请记住,我们通过在列名前加上表名来实现这一点。

本练习将回到本章前面使用过的 Chinook 数据库。

本练习是课程的一部分

SQL Server 入门

查看课程

交互式实操练习

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

-- SELECT the fully qualified album_id column from the album table
SELECT 
  ___,
  title,
  album.artist_id,
  -- SELECT the fully qualified name column from the artist table
  ___ as artist
FROM album
-- Perform a join to return only rows that match from both tables
INNER JOIN artist ON album.artist_id = artist.artist_id
WHERE album.album_id IN (213,214)
编辑并运行代码