Union
Explore how to combine results from different SQL queries using the UNION clause. Understand its syntax, requirements for column matching, handling duplicates, and the difference between UNION and UNION ALL. Practice writing queries that merge data sets while maintaining data integrity and compatibility.
Union
The UNION clause allows us to combine the results from several queries together. The clause doesn’t join the table but merely clubs the two results together.
Syntax
<Query1>
UNION
<Query2>
Connect to the terminal below by clicking in the widget. Once connected, the command line prompt will show up. Enter or copy and paste the command ./DataJek/Lessons/27lesson.sh and wait for the MySQL prompt to start-up.
-
As a contrived example, we’ll write a query that prints all the first names from the Actors table and all the URLs from the DigitalAssets table.
SELECT FirstName FROM