Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Introduction to SQL Server

Cursus bekijken

Oefeninstructies

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

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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
___ ___;
Code bewerken en uitvoeren