The University of Sydney · FACULTY OF INFORMATION TECHNOLOGY

ISYS2120 Chap.5 Relational Algebra and Advanced SQL

- one subject, every graph, every model, every mark
13 Chapters13-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 5 of 5 · ISYS2120

Relational Algebra and Advanced SQL

Relational Algebra and Advanced SQL exposes the intermediate relations behind a query. Selection keeps rows, projection keeps columns, set operators compare compatible relations, joins combine matching tuples, and rename resolves schema-level naming problems. Because every operator returns a relation, a complex expression can be traced one result at a time and rearranged with equivalence rules.

Relational division supplies the demanding universal pattern: find candidates connected to every required tuple. The SQL half extends that reasoning through GROUP BY and HAVING, NULL-aware aggregates, outer joins, nested subqueries and correlated EXISTS tests. Examination answers must translate among an English request, algebra and SQL without confusing SQL SELECT with algebraic selection.

The reliable endpoint is always a computed relation whose rows can be checked against the original stakeholder request.

In this chapter

What this chapter covers

  • 01

    Use algebra to expose query structure

  • 02

    Select rows before expensive combinations

  • 03

    Project attributes with intent

  • 04

    Rename to control scope

  • 05

    Construct and constrain products

  • 06

    Apply set operators compatibly

  • 07

    Recognise division questions

  • 08

    Translate algebra into SQL

  • 09

    Use subqueries for staged reasoning

  • 10

    Express universal conditions with NOT EXISTS

  • 11

    Compare inner and outer joins

  • 12

    Cross-check advanced queries

  • 13

    Prove two query forms are equivalent

Worked example · free

Use division for an all-tools request

Q [4 marks]. ToolStock(depot_id, tool) contains (D1,Hammer), (D1,Drill), (D2,Hammer), (D3,Hammer), (D3,Drill), (D3,Saw). Required(tool) contains (Hammer) and (Drill). Compute ToolStock divided by Required: which depots stock every required tool? The four marks shown are an AskSia practice allocation, not a University mark scheme.
  • +1The divisor Required contains Hammer and Drill, so a candidate depot must have a ToolStock tuple paired with each of those values.
  • +1D1 has both required pairs. D2 has Hammer but lacks Drill. D3 has both required pairs; its extra Saw tuple does not disqualify it.
  • +1Form the quotient on depot_id. Retain D1 and D3, and exclude D2 because one required pairing is missing.
  • +1Run the equivalent double-NOT-EXISTS SQL and compare its ordered output with the hand-computed quotient.
ToolStock / Required = {D1, D3}. The executed SQL counterpart is SELECT DISTINCT t.depot_id FROM ToolStock t WHERE NOT EXISTS (SELECT 1 FROM Required r WHERE NOT EXISTS (SELECT 1 FROM ToolStock x WHERE x.depot_id=t.depot_id AND x.tool=r.tool)) ORDER BY t.depot_id; Its result table is: depot_id; D1; D3. D2 fails because (D2,Drill) is absent; D3's extra Saw row is irrelevant to the universal requirement.
Sia tip — For division, write the complete divisor list first and tick every required pairing for each candidate. One unticked value removes that candidate; extra pairings do not.
Glossary

Key terms

Relational algebra
A language whose operands and results are relations. Expressions combine operators so each intermediate result can feed the next operation.
Relation
A set of tuples over named attributes and their domains. In the mathematical model, NULL, duplicate tuples and row order are absent.
Expression
A composition of relation variables, constant relations and operators that calculates a new relation.
Selection
An algebra operator that retains only tuples satisfying a Boolean predicate while preserving the input attributes.
Projection
An algebra operator that keeps the listed attributes and removes duplicate tuples from the resulting relation.
Set difference
The tuples that occur in the first union-compatible relation but not in the second. Corresponding attributes must share names and domains.
Theta-join
A join that pairs tuples from two relations and retains only combinations satisfying an explicit Boolean condition.
Rename
A schema-level algebra operator that gives a relation or its attributes new names so later operations are well defined.
Relational division
An operator returning candidates related to every tuple in a divisor relation. It expresses universal all-required-items requests.
GROUP BY
A SQL clause that partitions surviving rows into groups sharing the listed attribute values before aggregate results are formed.
HAVING
A SQL clause that filters completed groups using grouping attributes or aggregate conditions.
Outer join
A join that preserves specified unmatched input rows and supplies NULL for attributes from the missing side.
Correlated subquery
A nested query that refers to a row from its outer query and is evaluated in that row's context, often with EXISTS.
FAQ

Relational Algebra and Advanced SQL FAQ

Why use relational algebra when SQL already runs the query?

Algebra exposes the operator structure independently of SQL syntax. It makes selection, projection, joins, set operations and division visible, helping you locate accidental products and reason about equivalent query plans.

What must be true before applying a set operator?

The two inputs must be union compatible: corresponding attributes need compatible domains and aligned meanings. Matching column counts alone is insufficient if one position represents a member identifier and the other represents an event identifier.

Which information needs suggest relational division?

Look for universal language such as every required station or all active workshops. Division returns candidates related to every member of the divisor, unlike an ordinary join that establishes only at least one matching fact.

How does double NOT EXISTS express an all condition?

The outer query keeps a candidate when there does not exist a required item for which no matching fact exists. Both correlations matter; removing one can reverse the meaning or test an unrelated global condition.

When does a left join stop behaving like an outer join?

A condition on the nullable right side placed in WHERE can reject the NULL-extended unmatched rows, effectively restoring inner-join behaviour. Put the qualifying condition in ON when unmatched left rows must remain visible.

Study strategy

Exam move

Use a trace-table routine for relational algebra. Write the schema and tuples of every input, calculate one operator at a time, and label each intermediate relation before composing the final expression. Alternate translation directions: English to algebra, algebra to plain stakeholder purpose, SQL to algebra, and algebra back to SQL.

Keep the crucial vocabulary contrast visible: SQL SELECT corresponds to algebraic projection, while SQL WHERE corresponds to algebraic selection. For joins and set operations, verify schema compatibility before touching tuples. For division, list the divisor and audit every candidate against every required value.

In advanced SQL, run GROUP BY and HAVING on hand-counted groups, compare COUNT(*) with NULL-ignoring aggregates, and draw unmatched rows before choosing an outer join. Finish each session with one correlated subquery and its double-NOT-EXISTS reading. The examination rewards a meaningful request and a checkable resulting relation, so never stop at reciting operator names.

Working through Relational Algebra and Advanced SQL in ISYS2120? Sia is AskSia’s AI Information Technology tutor — ask any ISYS2120 Relational Algebra and Advanced SQL question and get a clear, step-by-step explanation grounded in how ISYS2120 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 64 of your The University of Sydney subjects - and 1,000+ Bibles across every Australian university.
Sia - your ISYS2120 tutor, unlimited, worked the way the exam marks it
The full 13-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works
Unlock the full ISYS2120 Bible + 64 The University of Sydney subjects
$0.99 Trial