The operator The INTEECT operator The EXCET operator QL language: basics The operator et union operator A B The operator It performs the union of the two relational expressions A and B relational expressions A and B may be generated by ELECT statements removal of duplicates removes duplicates ALL does not remove duplicates Name Color ize Jumper ed 40 2 Jeans Green 48 3 Blouse Blue 48 ome 4 Blouse ed 44 5 kirt Blue 40 horts ed 42 Id Qty 1 300 1 2 200 1 3 400 1 4 200 1 5 100 1 100 2 300 2 2 400 3 2 200 4 3 200 4 4 300 4 5 400 WHEE Color= ed Name Color ize Jumper ed 40 2 Jeans Green 48 3 Blouse Blue 48 ome 4 Blouse ed 44 5 kirt Blue 40 horts ed 42 2013 olitecnico di Torino 1
Find the codes of the products that are either red or Id Qty 1 300 1 2 200 1 3 400 1 4 200 1 5 100 1 100 2 300 2 2 400 3 2 200 4 3 200 4 4 300 WHEE Id= 2 2 D M BG 4 5 400 D M BG WHEE Color= ed WHEE Id= 2 ; 2 2 WHEE Color= ed WHEE Id= 2 ; Duplicate removal 2 chema compatibility WHEE Color= ed WHEE Id= 2 ; ALL: example WHEE Color= ed ALL WHEE Id= 2 ; 2 2 The INTEECT operator 2013 olitecnico di Torino 2
et intersection operator A INTEECT B The INTEECT operator It performs the intersection of the two relational expressions A and B relational expressions A and B may be generated by ELECT statements INTEECT: example Name Color ize Jumper ed 40 2 Jeans Green 48 3 Blouse Blue 48 ome 4 Blouse ed 44 5 kirt Blue 40 horts ed 42 1 mith 20 2 Jones 10 3 Blake 30 4 Clark 20 5 Adams 30 INTEECT: example INTEECT: example 1 mith 20 2 Jones 10 3 Blake 30 4 Clark 20 5 Adams 30 Name Color ize Jumper ed 40 2 Jeans Green 48 3 Blouse Blue 48 ome 4 Blouse ed 44 5 kirt Blue 40 horts ed 42 ome INTEECT: example Equivalence with other operators INTEECT ; ome The intersection operation may also be performed by means of a join the IN operator 2013 olitecnico di Torino 3
Equivalence with join The FOM clause contains the relations involved in the intersection The WHEE clause contains join conditions between the attributes listed in the ELECT clauses of relational expressions A and B Equivalence with join: example, WHEE.=.; Equivalence with the IN operator One of the two relational expressions is turned into a nested query using operator IN The attributes in the outer ELECT clause, joined together by a tuple constructor, make up the lefthand side of the IN operator Equivalence with IN: example WHEE IN ( ); The EXCET operator et difference operator A EXCET B It subtracts relational expression B from relational expression A The EXCET operator 2013 olitecnico di Torino 4
EXCET: example EXCET: example Name Color ize Jumper ed 40 2 Jeans Green 48 3 Blouse Blue 48 ome 4 Blouse ed 44 5 kirt Blue 40 horts ed 42 1 mith 20 2 Jones 10 3 Blake 30 4 Clark 20 5 Adams 30 1 mith 20 2 Jones 10 3 Blake 30 4 Clark 20 5 Adams 30 EXCET: example EXCET: example Name Color ize Jumper ed 40 2 Jeans Green 48 3 Blouse Blue 48 ome 4 Blouse ed 44 5 kirt Blue 40 horts ed 42 ome EXCET ; ome Equivalence with the NOT IN operator Equivalence with the NOT IN operator: example The difference operation may also be performed by means of the NOT IN operator relational expression B is nested within the NOT IN operator the attributes in the ELECT clause of relational expression A, joined together by a tuple constructor, make up the left-hand side of the NOT IN operator WHEE NOT IN ( ); 2013 olitecnico di Torino 5