=====
CS 325 - Week 10 Asynchronous Material - Part 2
=====
* SQL parts, now!
=====
SQL - more on those set-theoretic operations
=====
* in addition to UNION, SQL also supports additional set-theoretic
operations, including INTERSECT and MINUS
^ intersection operation
^ difference operation
* but we are talking sets of TUPLES, relations, of course;
so all three DO require so-called union-compatibility --
both relations need to have the same number of attributes,
and their domains need to be compatible!
* So, union of 2 relations R1 and R2, (R1 u R2)
* if a tuple is in R1, it is in (R1 u R2)
* if a tuple is in R2m it is in (R1 u R2)
* (and it can be in both R1 and R2, but it is in (R1 u R2) just once,
because in a set you care if something is a member of the set or not...
* Intersection of 2 relations R1 and R2, (R1 n R2)
* if a tuple is in R1 AND it is also in R2, then it is in (R1 n R2)
* Difference of 2 relations R1 and R2, (R1 - R2)
* if a tuple is in R1 AND it is also NOT in R2, then it is (R1 - R2)
* in SQL, the operators are UNION, INTERSECT, and MINUS
and these have operands that are sub-selects!
(desired sub-select)
union
(desired sub-select)
(desired sub-select)
intersect
(desired sub-select)
(desired sub-select)
minus
(desired sub-select)
* note: the column names you'll see will be those from the 1st sub-select
(whether column name, computation, or column alias)
* remember: the two sub-selects, for ANY of these three operations,
need to be UNION-compatible (same number of columns, whose types are
compatible)
* CS 325 course STYLE:
* we WILL write each of the sub-selects for a union, intersect, or minus
within a set of parentheses
* we will make sure the domains of the columns involved are also "mean"
the same thing (even though SQL can really only check for compatible types)
* IF you are ordering the result of a union, intersect, or minus,
then it should go AFTER the second sub-select operand,
AFTER its closing parenthesis (the overall union, intersect, or minus
is the "outer" select, in this case)