ComeçarComece gratuitamente

RIGHT JOIN

Vamos agora testar algumas junções RIGHT. Uma junção RIGHT retorna todas as linhas da tabela da direita, além de todas as correspondências da tabela da esquerda.

Além de realizar uma junção à direita, você também vai aprender a evitar problemas quando tabelas diferentes tiverem os mesmos nomes de coluna, qualificando totalmente a coluna na instrução select. Lembre-se de que isso é feito acrescentando ao nome da coluna um prefixo com o nome da tabela.

Neste exercício, voltaremos ao banco de dados Chinook do início do capítulo.

Este exercício faz parte do curso

Introdução ao SQL Server

Ver Curso

Exercício interativo prático

Experimente este exercício preenchendo este código de exemplo.

-- 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)
Editar e executar código