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.
This exercise is part of the course
Introduction to SQL Server
Exercise instructions
Make the first selection from the album
table. Then join the results by providing the relevant keyword and selecting from the artist
table.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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
___ ___;