시작하기무료로 시작하기

Inner Join (III) - 3개 테이블 조인

이미 albumtrack, 그리고 albumartist를 각각 조인하는 방법을 살펴봤어요. 이번 연습에서는 세 테이블을 모두 조인해서 더 완전한 결과 집합을 만들어 보겠습니다. 계속해서 INNER JOIN을 사용할 텐데, 이번에는 두 번 이상 지정해야 해요.

여기서 주의할 점은 trackartist 모두에 name 컬럼이 있으므로, 컬럼 이름 앞에 해당 테이블 이름을 접두사로 붙여서 선택 위치를 qualify해야 한다는 것입니다.

이 연습은 강의의 일부입니다

SQL Server 입문

강의 보기

연습 안내

  • 두 경우 모두 올바른 테이블 접두사를 지정해 name 컬럼을 명시하세요.
  • albumtrack, 그리고 artistalbum을 조인하도록 두 개의 INNER JOIN 절을 완성하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

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.___;
코드 편집 및 실행