0
0
MySQLquery~30 mins

Why combining result sets is useful in MySQL - See It in Action

Choose your learning style9 modes available
Why Combining Result Sets is Useful
📖 Scenario: You work at a small bookstore that tracks sales in two separate tables: online_sales and store_sales. You want to see all sales together to understand total sales better.
🎯 Goal: Build a combined list of all sales from both online_sales and store_sales tables using SQL UNION to see all sales in one result set.
📋 What You'll Learn
Create two tables: online_sales and store_sales with columns sale_id and amount
Insert exact sales data into both tables
Write a SQL query using UNION to combine sales from both tables
Order the combined results by sale_id
💡 Why This Matters
🌍 Real World
Combining sales data from different sources helps businesses get a complete view of their transactions.
💼 Career
Database professionals often combine data from multiple tables or databases to create reports and insights.
Progress0 / 4 steps
1
Create the sales tables
Create two tables called online_sales and store_sales. Each table should have two columns: sale_id as an integer and amount as a decimal number.
MySQL
Need a hint?

Use CREATE TABLE statements with the exact column names sale_id and amount.

2
Insert sales data
Insert these exact rows into online_sales: (1, 15.50), (2, 23.75). Insert these exact rows into store_sales: (3, 10.00), (4, 5.25).
MySQL
Need a hint?

Use INSERT INTO with the exact values for each table.

3
Combine sales with UNION
Write a SQL query that uses UNION to combine all rows from online_sales and store_sales. Select sale_id and amount from both tables.
MySQL
Need a hint?

Use SELECT from each table and combine with UNION.

4
Order the combined results
Add an ORDER BY sale_id clause at the end of your UNION query to sort all sales by sale_id.
MySQL
Need a hint?

Place ORDER BY sale_id after the UNION query to sort results.