Database Querying: Relational Algebra 2 -- Union, Intersection, and Set Difference
Thomas Blum Thomas Blum
408 subscribers
12 views
0

 Published On Sep 16, 2024

In this video we continue our discussion of "Relational Algebra" -- ways of combining tables (relations) in SQL queries. We start with two queries that are "union compatible" (have the same number of fields with the same types in the same order). These results can then be treated as "sets". From them we can construct the union which has all members (rows) from each set (with duplications eliminated). We can also construct the intersection which contains only elements (rows) belonging to both sets (query results). Finally we can obtain the "set difference" which eliminates from the first set (table) anything in the intersection. Our examples were originally created in Microsoft's Access database. We "constructed" the intersection in two ways: first a join (but not a "natural" join) and second using a subquery. We finally made the set difference by changing then IN in the subquery approach to a NOT IN.

show more

Share/Embed