From the course: SQL Hands-On Practice: Solve Business Problems
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Combining multiple data sources with UNION - SQL Tutorial
From the course: SQL Hands-On Practice: Solve Business Problems
Combining multiple data sources with UNION
- [Instructor] To solve this problem, we're going to use UNION. Similar to JOIN, UNION combines data sets together. However, unlike JOINs, UNION combines data sets vertically by stacking multiple select statements, kind of like making a sandwich. UNION also ensures that all duplicate rows are removed and excluded from the output. If you want to keep the duplicates, you can use UNION ALL instead. There are a few rules of UNION that we'll go over in the next video. But let's solve this problem really quick as an example, to see how it works. We're going to combine three different data sources into one output. We have website leads, prospects, and users. And we have to combine all of these into one output. We're first going to start with select, name, email, FROM, the websiteleads table. And let's run this to see what it looks like. Here, we have a list of all of the names and emails from the websiteleads table.…