different ways to join tables
cross join, inner join, outer join
inner join aka and types
“old-style” join
- equijoin
- theta join
JOIN ON
outer join types
left join, right join
mandatory and optional (order mandatory)
mandatory: SELECT, FROM
optional: WHERE, GROUP BY, HAVING, ORDER BY
cross join format
select column_list from table1, table2
cross join provides the _____
cartesian product of 2 tables
cross join result
single table of info
# cols = # cols selected (tb1) + # cols selected (tb2)
rows = # rows (tb1) * # rows (tb2)
“old style” inner join format
select column_list from table1, table2
where table1.col1 = table2.col2
“join on” inner join format
select column_list from table1 join table2 on table1.col1 = table2.col2
if fk and pk have same name, how would you do join on
select column_list from table1 join table2 using (col1)
an inner join is a
traditional join in which only rows that meet given criteria are selected
if inner join criteria involves equality, it is called
equijoin or natural join
if join criteria involves an inequality, it is called a
theta join
an inner join typically uses _____ to link tables together
PK - FK relationship
self-join
type of inner join, used to find information by comparing rows within same table
self-join format (T1 and T2 are aliases)
select column_list from table1 T1, table2 T2 where T1.col1 = T2.col2
t/f: table aliases can be used in any type of join
true
general approach for inner joins with multiple tables
general approach: include tables that lie between these tables
every table must be linked directly to another to avoid cross joins
general approach: include table linkages to tie all tables together
where (e.pk = f.fk) and (f.pk = g.pk) and…
general approach: further restrict rows as necessary
(where x=y)