IniziaInizia gratis

Join the UNION

You can write 2 or more SELECT statements and combine the results using UNION. For example, you may have two different tables with similar column types. If you wanted to combine these into one set of results, you'd use UNION. You'll see how to do this using the artist and album tables. In this exercise, you'll SELECT two common columns, add a description, then a Source column so you can tell which table the columns originated from.

Questo esercizio fa parte del corso

Introduction to SQL Server

Visualizza il corso

Istruzioni dell'esercizio

Make the first selection from the album table. Then join the results by providing the relevant keyword and selecting from the artist table.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

SELECT 
  album_id AS ID,
  title AS description,
  'Album' AS Source
  -- Complete the FROM statement
FROM ___
 -- Combine the result set using the relevant keyword
___
SELECT 
  artist_id AS ID,
  name AS description,
  'Artist'  AS Source
  -- Complete the FROM statement
___ ___;
Modifica ed esegui il codice