0
0
SQLquery~30 mins

UNION combining result sets in SQL - Mini Project: Build & Apply

Choose your learning style9 modes available
Combine Customer and Supplier Names Using UNION
📖 Scenario: You work for a company that has two separate tables: one for customers and one for suppliers. Both tables have a column called name that stores the names of people or companies.Your manager wants a single list of all unique names from both tables combined.
🎯 Goal: Create a SQL query that uses UNION to combine the name columns from the customers and suppliers tables into one list without duplicates.
📋 What You'll Learn
Use the customers table with a name column
Use the suppliers table with a name column
Write a SQL query that selects name from both tables
Combine the results using UNION to remove duplicates
Order the final result by name alphabetically
💡 Why This Matters
🌍 Real World
Combining data from different sources to create unified reports or lists is common in business databases.
💼 Career
Knowing how to use UNION helps database professionals merge data cleanly without duplicates, which is essential for accurate reporting.
Progress0 / 4 steps
1
Create the customers table with sample data
Write SQL statements to create a table called customers with a column name of type VARCHAR(50). Insert these exact names into customers: 'Alice', 'Bob', 'Charlie'.
SQL
Need a hint?

Use CREATE TABLE customers (name VARCHAR(50)); and then INSERT INTO customers (name) VALUES ('Alice'), ('Bob'), ('Charlie');

2
Create the suppliers table with sample data
Write SQL statements to create a table called suppliers with a column name of type VARCHAR(50). Insert these exact names into suppliers: 'Bob', 'Diana', 'Edward'.
SQL
Need a hint?

Use CREATE TABLE suppliers (name VARCHAR(50)); and then INSERT INTO suppliers (name) VALUES ('Bob'), ('Diana'), ('Edward');

3
Write a query to select names from customers
Write a SQL query that selects the name column from the customers table.
SQL
Need a hint?

Use SELECT name FROM customers; to get the names from customers.

4
Combine names from customers and suppliers using UNION
Write a SQL query that selects the name column from customers and combines it with the name column from suppliers using UNION. Order the combined results by name alphabetically.
SQL
Need a hint?

Use SELECT name FROM customers UNION SELECT name FROM suppliers ORDER BY name; to combine and sort names.