From the course: MySQL Data Analysis

Unlock this course with a free trial

Join today to access over 24,600 courses taught by industry experts.

UNION example

UNION example

- [Instructor] Okay, now let's walk through an example with UNION. So UNION allows us to combine the results of two or more SELECT statements into one single result set. You're going to want to think of UNION as stacking two results sets on top of each other. So when we use joins, we're making tables that were wider, they had more columns. When we use UNION, we're making tables that are longer, they get more records, more rows. Each SELECT statement that you include in your UNION must have the same number of columns. And the stacked columns must be in compatible formats. So you can't have a varying character stacked on top of an integer. That's going to break your UNION. Let's jump into Workbench and go through an example. All right, so here, I've got a UNION. Before I run the full UNION, I want to just show you guys what it looks like to run each individual query. So I've commented out this whole UNION and the second SELECT statement, and I'm just going to run this first query. So…

Contents