Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
UNION
6. How UNION works
INTERSECT
EXCEPT

Instruction

Let's start off with a new keyword: UNION. What is a union? Well, long story short, it combines the results of two or more queries. Let's analyze the example:

SELECT
  *
FROM Cycling
WHERE Country = N'Germany'

UNION

SELECT
  *
FROM Skating
WHERE Country = N'Germany';

As you can see, we first selected all medals for Germany from the Cycling table. Then, we used the UNION keyword, after which we selected all medals for Germany from the Skating table.

You may be wondering whether we could've split this instruction into two separate queries. Of course we could have! But using a UNION, we get all results for the first table plus the results of the second table shown together. Remember to only put the semicolon (;) at the very end of the whole instruction!

Exercise

Show all the medals for the period between 2010 and 2014 for skating and cycling. Use the UNION keyword.

Stuck? Here's a hint!

Type:

SELECT
  *
FROM Cycling
WHERE Year BETWEEN 2010 AND 2014
UNION
SELECT
  *
FROM Skating
WHERE Year BETWEEN 2010 AND 2014;