1 of 12

CSE 414 Section 6:

Midterm Prep

November 5th, 2026

2 of 12

Announcements

  • HW4 due Monday, Nov 9th @ 11:59pm
  • HW3 grades back tonight
  • Midterm tomorrow during lecture time – Covers everything from beginning of the class up to (and including) Relational Algebra

​

3 of 12

Database Fundamentals

  • A relational database stores data in tables (relations)
  • Rows = tuples; columns = attributes
  • Schema = structure of a table
  • Instance = actual data currently stored
  • Primary key: uniquely identifies each row; cannot be NULL
  • Foreign key: references a key in another table

4 of 12

SQL Basics

  • SELECT: which columns
  • FROM: which table
  • WHERE: which rows
  • DISTINCT: remove duplicates
  • WHERE: keeps rows where condition is TRUE
  • NULL: missing or unknown value
  • Use IS NULL, not = NULL
  • 3-valued logic: TRUE, FALSE, UNKNOWN

5 of 12

SQL Joins

  • Joins combine information from multiple tables
  • Join conditions determine which rows match
  • An inner join keeps matching pairs
  • Missing a join condition can produce a Cartesian product

6 of 12

SQL Joins (2)

Inner join - only keep matching rows

Left join - all left rows + matching right rows

Right join - all right rows + matching left rows

Full join - all rows from both sides

Self join - Join a table with itself

Cartesian product - cross join (all possible combinations of rows)

6

7 of 12

SQL Aggregates

  • COUNT(*): Count number of all rows
  • COUNT(column): Count non-NULL values
  • SUM(): Total
  • AVG(): Average
  • MIN() / MAX(): Minimum / maximum
  • Most aggregates ignore NULL values

8 of 12

SQL Filtering & Conditions

  • WHERE : Filters individual rows before grouping
  • HAVING: Filters groups after aggregation
  • GROUP BY: Creates groupings of rows
  • AND, OR, NOT: Combine or negate conditions
  • IN: Checks whether a value belongs to a set (opposite is NOT IN)
  • EXISTS: TRUE if a subquery returns at least one row (opposite is NOT EXISTS)

9 of 12

SQL Logical Evaluation Order

FWGHOSTM

(From, Where, Group By, Having, Order By, Select)

9

10 of 12

SQL Subqueries

  • A query nested inside another query
  • Can return a single value or a relation
  • Can appear in SELECT, FROM, WHERE, or HAVING
  • Useful for breaking a complex problem into smaller steps (but don’t use too many!)

11 of 12

SQL Relational Algebra

11

Operator

Symbol

Description

Selection

σ (sigma) / WHERE

Filters rows that satisfy a condition.

Projection

π (pi) / SELECT

Chooses specific attributes (columns). Eliminates duplicates in pure RA.

Join

⋈ (bowtie) / JOIN

Combines rows based on a join condition

Grouping & Aggregation

γ (gamma) / GROUP BY

Groups rows and computes aggregates

Sorting

τ (tau) / ORDER BY

Sorts rows by specified attributes

Duplicate Elimination

δ (delta) / DISTINCT

Removes duplicate rows

12 of 12

SQL Relational Algebra Format

  • Follows FWGHOS structure

​

12