Unioning data in SQL is just "glueing" one result onto the bottom of another -- it combines the rows from two (or more!) results. Although there aren't any great examples with the AdventureWorks data, this is an important way to combine data in SQL.
Note that if you're not using Microsoft SQL Server, check out the documentation for your SQL flavour to see whether ROLLUP is supported.
The dbfiddle website can be accessed for free and without an account at:
dbfiddle.uk/
Make sure to use the SQL Server dialect and the AdventureWorks sample database to be able to follow along with these examples!
---------------------------------------------------
This is part of the From Excel to SQL playlist, available at:
• From Excel to SQL
Check out the previous video at:
• From Excel to SQL - Joins (JOIN)
...and the next video at:
• From Excel to SQL - Subqueries
The written version of this content is also available at:
bilbottom.github.io/sql-learning-materials/from-ex…
---------------------------------------------------
CHAPTERS
00:00 dbfiddle
00:28 Intro
01:03 Using UNION
03:06 Multiple UNIONs
04:07 Rule: Column data types must match
05:48 Rule: Number of columns must match
06:11 UNION removes duplicates
06:58 UNION ALL keeps duplicates
07:28 Wrap up
コメント