8 Displaying Data from Multiple Tables

0.0(0)
studied byStudied by 1 person
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/89

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

90 Terms

1
New cards

What is a SQL join?

A SELECT that retrieves and merges rows from two or more tables based on related columns.

2
New cards

What is an inner join?

A join that returns a merged row only when matching values exist in all joined tables.

3
New cards

What is an outer join?

A join that returns matched rows and also includes nonmatching rows from one or both tables with NULLs for missing columns.

4
New cards

List the three outer join types.

LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN.

5
New cards

What is an equijoin?

A join that matches rows using equality of column values between tables.

6
New cards

What is a non-equijoin?

A join that relates rows using non-equality comparisons such as

7
New cards

What is a natural join?

A join that automatically matches tables by columns with identical names; join columns aren't explicitly listed.

8
New cards

What is a self-join?

A join where a table is joined to itself, usually matching one column to a different column in the same table.

9
New cards

Can joins include more than two tables?

Yes. Joins can include three or more tables; FROM appears once and additional tables are added with JOIN … ON.

10
New cards

Are PRIMARY KEY and FOREIGN KEY constraints required to perform a join?

No. They help integrity but are not required for performing joins.

11
New cards

Show the ANSI inner join skeleton.

SELECT … FROM t1 JOIN t2 ON t1.col = t2.col;

12
New cards

Is INNER optional in INNER JOIN?

Yes. JOIN without INNER defaults to INNER JOIN.

13
New cards

Is ON required in ANSI joins (when not using NATURAL or USING)?

Yes. ON is required to specify the join condition.

14
New cards

Can a WHERE clause be used with an inner join?

Yes. WHERE filters the joined result after the join condition.

15
New cards

What happens to rows with NULL foreign keys in an inner join?

They are excluded because no match exists in the joined table.

16
New cards

What is the older Oracle inner join syntax?

List both tables in FROM and place the equality condition in WHERE, e.g., FROM A, B WHERE A.id = B.id.

17
New cards

Is the older Oracle join syntax ANSI-compliant?

No. It works in Oracle but is not ANSI standard; ANSI JOIN … ON is preferred.

18
New cards

What is a table alias?

A temporary name assigned to a table in a SQL statement for brevity and disambiguation.

19
New cards

How long does a table alias last?

Only for the duration of the SQL statement where it is declared.

20
New cards

When are table aliases necessary?

When two or more joined tables have columns with the same name to avoid ambiguity.

21
New cards

Where can table aliases be used besides SELECT?

In INSERT, UPDATE, DELETE, and MERGE statements.

22
New cards

How do you define table aliases?

After each table name in FROM, add a space and the alias, e.g., FROM employees em JOIN addresses ad …

23
New cards

If two tables both have EMPLOYEE_ID, how do you reference it unambiguously?

Prefix with table or alias like em.employee_id or ad.employee_id.

24
New cards

What columns does NATURAL JOIN use?

All columns that have identical names in both tables.

25
New cards

Is NATURAL JOIN an inner or outer join by default?

Inner by default; can be LEFT/RIGHT/FULL if specified.

26
New cards

Are table prefixes allowed on join columns in NATURAL JOIN?

No. Prefixed references to the join columns cause a syntax error.

27
New cards

From which table is an unqualified common column sourced in NATURAL JOIN (inner or left)?

From the leftmost table.

28
New cards

From which table is an unqualified common column sourced in NATURAL RIGHT JOIN?

From the rightmost table.

29
New cards

How is a common column sourced in NATURAL FULL OUTER JOIN?

From the combination of both tables’ rows as returned in the full outer join.

30
New cards

What does the USING clause do in a join?

Specifies one or more identically named columns to join on without table prefixes.

31
New cards

Are table prefixes allowed with columns listed in USING?

No. You cannot prefix these columns anywhere in the statement.

32
New cards

How do join columns behave in the SELECT list with USING in an outer equijoin?

The output shows a value if present in either table’s join column; otherwise NULL.

33
New cards

Can USING join on multiple columns?

Yes. List multiple columns inside USING(…).

34
New cards

How do you extend a two-table join to a third table?

Append JOIN third_table alias ON … after the first join; FROM appears once.

35
New cards

What are practical considerations for many-table joins?

Performance and maintenance complexity increase; many practitioners keep joins around five tables, context dependent.

36
New cards

What is the structure of a three-table join?

FROM A a JOIN B b ON … JOIN C c ON … with each ON defining its join condition.

37
New cards

Give an example of a non-equijoin condition.

ON s.testscore BETWEEN g.scoremin AND g.score_max.

38
New cards

Do non-equijoins require PK/FK relationships?

No. They match based on comparison logic, not keys.

39
New cards

What operators are valid in non-equijoins?

, >=, <, <=, BETWEEN, and comparisons using expressions and Boolean logic.

40
New cards

How do you reference the same table twice in a self-join?

List the table twice in FROM with different aliases and join columns accordingly.

41
New cards

Why might a LEFT OUTER self-join be used with hierarchical data?

To include top-level rows with no parent (e.g., REPORTS_TO is NULL).

42
New cards

Is a self-referencing foreign key required for a self-join?

No. It helps integrity but is optional for the join.

43
New cards

What columns are typically joined in a self-join for reporting lines?

Child.REPORTS_TO joined to Parent.POSITION_ID.

44
New cards

Can a self-join be written as a non-equijoin?

Yes. Self-joins can be inner/outer and equi/non-equi as needed.

45
New cards

What does LEFT OUTER JOIN guarantee?

All rows from the left table appear; matching rows from the right table appear when present, else NULLs.

46
New cards

What does RIGHT OUTER JOIN guarantee?

All rows from the right table appear; matching rows from the left table appear when present, else NULLs.

47
New cards

What does FULL OUTER JOIN guarantee?

All rows from both tables appear, matched where possible and standalone otherwise with NULLs.

48
New cards

Is the OUTER keyword mandatory in outer joins?

No. OUTER is optional; LEFT JOIN equals LEFT OUTER JOIN, etc.

49
New cards

Where does JOIN appear in a multitable outer join?

After FROM on the first pair, then successive JOIN … ON clauses for additional tables.

50
New cards

What is the Oracle outer join plus operator?

A legacy syntax placing (+) on the side of the nonpreserved table in a WHERE equijoin predicate.

51
New cards

How do you express a left outer join with (+)?

Put (+) on the right-side table’s column in the WHERE equality, e.g., A.id = B.id(+).

52
New cards

How do you express a right outer join with (+)?

Put (+) on the left-side table’s column, e.g., A.id(+) = B.id.

53
New cards

Can you express FULL OUTER JOIN with (+)?

Not directly; you must UNION a left and a right outer join to simulate it.

54
New cards

Should you use the (+) operator today?

Oracle recommends avoiding it; use ANSI JOIN syntax. It is not tested on the exam.

55
New cards

What error occurs if you reference an ambiguous column without a prefix?

SQL raises an 'ambiguous column' error; you must prefix with a table or alias.

56
New cards

When does ambiguity commonly occur in joins?

When both tables have a column with the same name (e.g., EMPLOYEE_ID).

57
New cards

How do NATURAL and USING affect ambiguity handling?

They remove the need to prefix the join columns and disallow prefixes for those columns.

58
New cards

Where do GROUP BY and HAVING appear relative to JOIN and WHERE?

JOIN and WHERE form the row set first; GROUP BY and HAVING follow; ORDER BY is last if used.

59
New cards

Where does FROM appear in a JOIN query?

Once at the start of the table list; subsequent tables are added using JOIN.

60
New cards

In the SHIPS table, how is a home port recorded?

By a HOMEPORTID foreign key referencing PORTS.PORT_ID.

61
New cards

Why might 'Miami' not appear in an inner join of SHIPS and PORTS?

No ship has HOMEPORTID = PORT_ID of Miami; inner join returns only matches.

62
New cards

What is returned for join columns when a USING-based outer join includes an unmatched row?

NULL for the side with no value; otherwise the existing value appears.

63
New cards

Summarize the difference between EQUJOIN and NON-EQUIJOIN.

Equijoin uses equality on key columns; non-equijoin uses relational comparisons or ranges.

64
New cards

Summarize the difference between INNER and OUTER joins.

Inner returns only matched rows; outer returns matched rows plus nonmatching rows from the preserved side(s).

65
New cards

Can NATURAL JOIN be combined with outer joins?

Yes. NATURAL can be combined with LEFT, RIGHT, or FULL.

66
New cards

What does USING enable compared to NATURAL?

Explicitly names the common join columns instead of inferring all identically named columns.

67
New cards

Do joins require identical column names?

No for ON; Yes for NATURAL and USING (for the specified columns).

68
New cards

Self test: What does an inner join look for?

Values that match between the joined tables.

69
New cards

Self test: Which operator is characteristic of non-equijoins among options !=, <>, <=, none?

70
New cards

Self test: What do equijoins look for?

Exact data matches.

71
New cards

Self test: In 'SELECT … FROM A INNER JOIN B ON …', which keyword is optional?

INNER.

72
New cards

Self test: With JOIN … USING(VENDOR_ID), does the statement need ON?

No. USING replaces ON and the statement executes successfully.

73
New cards

Self test: JOIN … USING(VENDOR_ID) is what kind of join by default?

INNER equijoin.

74
New cards

Self test: What are two truths about table aliases?

They exist only for the statement and can remove ambiguity.

75
New cards

Self test: A query joining POSITIONS, EMPLOYEES, and PAY_HISTORY without aliases—valid?

Yes, it can execute successfully and connects three tables.

76
New cards

Self test: Is 'JOIN … ON p.salary BETWEEN pos.min_salary AND pos.max_salary' a non-equijoin?

Yes. It is a non-equijoin and also an inner join if INNER is implied.

77
New cards

Self test: How many tables can you join in one query?

One, two, three, or more; there is no fixed upper limit in SQL.

78
New cards

Self test: To list all customers and any purchases in last two weeks, which join?

An OUTER equijoin between CUSTOMERS and PURCHASES.

79
New cards

Self test: What characterizes a self-join?

Same table named twice in FROM and joined column-to-column within that table.

80
New cards

Self test: Is there a SELF JOIN keyword in Oracle?

No. You use standard JOIN syntax with aliases, not SELF JOIN.

81
New cards

Self test: Which outer join syntaxes are correct?

LEFT JOIN … ON … and RIGHT OUTER JOIN … ON … are both correct.

82
New cards

Self test: Key difference between INNER and OUTER joins?

INNER shows only matches; OUTER includes nonmatching rows as well.

83
New cards

Can NATURAL JOIN match multiple columns automatically?

Yes. It uses all identically named columns across both tables.

84
New cards

Risk of NATURAL JOIN in evolving schemas?

Adding a same-named column later can silently change join behavior; use USING/ON for control.

85
New cards

Does JOIN order (LEFT vs RIGHT) change which nonmatching rows are preserved?

Yes. LEFT preserves left table rows; RIGHT preserves right table rows.

86
New cards

Can WHERE filter rows after an outer join and accidentally remove preserved NULL-extended rows?

Yes. Conditions on the nonpreserved table must be written carefully (e.g., move to ON or use IS NULL checks).

87
New cards

Does JOIN … ON support expressions and functions in join conditions?

Yes. You can use expressions, functions, and boolean combinations in the ON clause.

88
New cards

What happens if join keys have multiple matches (1:N) on both sides?

The join returns the Cartesian set of matching pairs for those rows.

89
New cards

When joining many tables, what readability practice helps?

Use concise table aliases and align JOIN … ON blocks clearly.

90
New cards

Does FULL OUTER JOIN combine effects of LEFT and RIGHT?

Yes. It includes all unmatched rows from both sides plus matched rows.