From the course: SQL for Non-Programmers

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Combining data with UNION

Combining data with UNION - SQL Tutorial

From the course: SQL for Non-Programmers

Combining data with UNION

We have practiced single-table queries as well as using joins for multi-table queries, but there also exists a way to perform two or more SELECT statements on a single table or multiple tables without using a join. The UNION operator can help us with this. The UNION operator allows you to combine the results of two or more SELECT statements within a single query using the same syntax. You can combine the results of multiple queries from a single table, or combine the results of multiple queries pulling from different tables. Let's move over to SLS and see how we can use UNIONs to answer questions about our Two Trees Olive Oil data. Management has requested a list of orders made by business customers. They also want to include all olive oil orders, regardless of which type of customer made the order. They need us to report back with the order number and the order total. These are two separate filter conditions that could be addressed with a WHERE clause. SELECT order number, customer…

Contents