SQL part 4 Flashcards

(21 cards)

1
Q

different ways to join tables

A

cross join, inner join, outer join

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

inner join aka and types

A

“old-style” join
- equijoin
- theta join
JOIN ON

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

outer join types

A

left join, right join

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

mandatory and optional (order mandatory)

A

mandatory: SELECT, FROM
optional: WHERE, GROUP BY, HAVING, ORDER BY

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

cross join format

A

select column_list from table1, table2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

cross join provides the _____

A

cartesian product of 2 tables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

cross join result

A

single table of info
# cols = # cols selected (tb1) + # cols selected (tb2)

rows = # rows (tb1) * # rows (tb2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

“old style” inner join format

A

select column_list from table1, table2
where table1.col1 = table2.col2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

“join on” inner join format

A

select column_list from table1 join table2 on table1.col1 = table2.col2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

if fk and pk have same name, how would you do join on

A

select column_list from table1 join table2 using (col1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

an inner join is a

A

traditional join in which only rows that meet given criteria are selected

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

if inner join criteria involves equality, it is called

A

equijoin or natural join

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

if join criteria involves an inequality, it is called a

A

theta join

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

an inner join typically uses _____ to link tables together

A

PK - FK relationship

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

self-join

A

type of inner join, used to find information by comparing rows within same table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

self-join format (T1 and T2 are aliases)

A

select column_list from table1 T1, table2 T2 where T1.col1 = T2.col2

17
Q

t/f: table aliases can be used in any type of join

18
Q

general approach for inner joins with multiple tables

A
  • specify attributes to be displayed or referenced
  • include tables from which those attributes come
  • include tables that lie between these tables
  • include table linkages to tie all tables together
  • further restrict rows as necessary
19
Q

general approach: include tables that lie between these tables

A

every table must be linked directly to another to avoid cross joins

20
Q

general approach: include table linkages to tie all tables together

A

where (e.pk = f.fk) and (f.pk = g.pk) and…

21
Q

general approach: further restrict rows as necessary