Modules
Data Analyst
Data Engineer
Product Data Scientist
AI Engineer
Machine Learning Engineer
Prompt Engineer
The SQL UNION operator is a tool used to combine the data from two separate tables.

Let's say Table 1 have values A, B, C & D and Table 2 has C, D, E & F.
Let's say you have 2 tables: employees and clients
employees table has the following columns:
| employee_id | employee_name | city |
|---|---|---|
| 1001 | John Doe | New York |
| 1002 | Jane Smith | Los Angeles |
| 1003 | Alice Johnson | New York |
| 1004 | Mike Brown | Chicago |
| 1005 | Karen White | New York |
And here is a sample of the clients table:
| client_id | client_name | city |
|---|---|---|
| 1001 | John Doe | New York |
| 1002 | Sarah Miller | San Francisco |
| 1003 | Rachel Green | New York |
| 1004 | David Turner | Boston |
| 1005 | Emma Watson | New York |
You're being asked to pull the list of all the client_name and their corresponding city, here is how it looks in SQL:
SELECT employee_name, city FROM employees
UNION ALL
SELECT client_name, city FROM clients
When I do it using UNION ALL, it doesn't remove duplicate so my result will be as follow:
| employee_name | city |
|---|---|
| John Doe | New York |
| Jane Smith | Los Angeles |
| Alice Johnson | New York |
| Mike Brown | Chicago |
| Karen White | New York |
| John Doe | New York |
| Sarah Miller | San Francisco |
| Rachel Green | New York |
| David Turner |
John Doe got repeat twice because UNION ALL doesn't remove duplicate. If you run it using UNION, it will remove John Doe from the list.
Let's practice now!

| Boston |
| Emma Watson | New York |