DB2 Unit 7
DB2 Unit 7
DB2 Unit 7
Page 2 of 13
Matches one table to another based on data common between the tables
Join Predicate Columns with identical characteristics Result Table contains rows comprised of columns from all the tables in the join
There is NO JOIN VERB May join up to 15 tables May join a table to itself (reflexive)
DB2_Tr Ver. 1.0.0 04/12/1998 Page 3 of 13
Page 4 of 13
Page 5 of 13
Page 6 of 13
select b.fname || ' ' || b.lname , b.department from staff a , staff b where b.department = a.department and a.empid = 110;
Page 7 of 13
Page 8 of 13
12 UNION
Objectives - Student will
Understand how to code a UNION
Page 9 of 13
12 UNION
Merge the results of two or more queries Removes duplicate rows Each SELECT must contain the same number of expressions (columns) Corresponding expressions must be the comparable data types
Page 10 of 13
12 UNION
Example 54
select 'Part ' ', pno, 'Made in England
from part
where city = 'london' UNION select 'Supplier', England' from supplier where city = 'london' order by 2 desc;
DB2_Tr Ver. 1.0.0 04/12/1998 Page 11 of 13
sno, 'Located in
12 UNION
UNION ALL
Includes all rows returned (does not eliminate duplicates)
Page 12 of 13
12 UNION
Example 55/56
',
pno
',
pno
where city = 'london' UNION ALL select Part from partsupp order by 1; , pno
where city = 'london' UNION select Part from partsupp order by 1; , pno
Page 13 of 13