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 - MySQL Tutorial
From the course: MySQL Data Analysis
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Introduction30s
-
(Locked)
Normalization and Cardinality3m 47s
-
(Locked)
Relationship diagrams1m 10s
-
(Locked)
Multi-table querying1m 4s
-
(Locked)
Reviewing the maven movies database1m 44s
-
(Locked)
Common JOIN types2m 25s
-
(Locked)
INNER JOIN1m 31s
-
(Locked)
INNER JOIN example5m 49s
-
(Locked)
Challenge: INNER JOIN42s
-
(Locked)
Solution: INNER JOIN4m 13s
-
(Locked)
LEFT JOIN1m 39s
-
(Locked)
LEFT JOIN example4m 43s
-
(Locked)
Challenge: LEFT JOIN42s
-
(Locked)
Solution: LEFT JOIN3m 57s
-
(Locked)
RIGHT JOIN1m 41s
-
(Locked)
LEFT vs. INNER vs. RIGHT JOIN3m 18s
-
(Locked)
FULL OUTER JOIN1m 27s
-
(Locked)
Pro tip: Bridging unrelated tables6m 51s
-
(Locked)
Challenge: Bridging tables57s
-
(Locked)
Solution: Bridging tables4m 25s
-
(Locked)
Multi-condition joins2m 40s
-
(Locked)
Challenge: Multi-condition joins44s
-
(Locked)
Solution: Multi-condition joins4m 42s
-
(Locked)
The UNION operator2m 15s
-
(Locked)
UNION example3m 51s
-
(Locked)
Challenge: The UNION operator32s
-
(Locked)
Solution: The UNION operator2m 41s
-
(Locked)
-