Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
UNION clause | Joining Tables

Course Content

Intermediate SQL

## UNION clause

Sometimes it is convenient to combine the result of several queries into one continuous result. For this purpose, SQL has the UNION operator.

But we have two different UNION clauses:

1. UNION ALL - duplicates are included;
2. UNION - duplicates are excluded.

Let's take a look at the syntax of using this operator.

It is time to practice!

You have to make two queries and combine them using the UNION operator:

1. Find the longest flight (create a new column named time using the MAX() function and travel_time column, take it from the flights table);
2. Find the shortest flight (create a new column named time using the MIN() function and travel_time column, take it from the flights table).

Here's a short example of the flights table:

 flight_number start_point_flight end_point_flight travel_time 1 Paris New York 8 2 Chicago New Delhi 15 3 New York Dubai 12 4 Los Angeles Honolulu 5

Everything was clear?

Section 3. Chapter 8

Course Content

Intermediate SQL

## UNION clause

Sometimes it is convenient to combine the result of several queries into one continuous result. For this purpose, SQL has the UNION operator.

But we have two different UNION clauses:

1. UNION ALL - duplicates are included;
2. UNION - duplicates are excluded.

Let's take a look at the syntax of using this operator.

It is time to practice!