RIGHT JOIN
現在來試試看 RIGHT join。RIGHT join 會回傳右表的所有列,以及左表中能對應到的列。
除了練習 RIGHT join,你也會學到當不同資料表有相同欄位名稱時,如何在 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)