Skip to main content
Practice library v1

Relational Algebra Exercises

Work from basic selection and projection through joins, set operations, and division. Each exercise ships with its own dataset snapshot, progressive hints, and a worked solution. Answers are graded by result semantics, not by matching expression text.

Difficulty
Operator focus
ex-begin-selection
Beginner

High achievers

List every student whose GPA is at least 3.8. Return all columns from Students (do not project yet).

σ
Selection (Restrict)
ex-begin-projection
Beginner

Department names only

Return the distinct department names from Departments.

π
Projection
ex-begin-rename-relation
Beginner

Alias a relation

Rename Students to S, then project student_id. Your result should list every student_id unchanged.

ρρ
Relation Rename
ex-begin-natural-join
Beginner

Employee departments

Show each employee name with their department name. Use a natural join on dept_id, then project name and dept_name.

⋈π
Natural Join
ex-begin-compose
Beginner

Engineering roster

List employee and department names only for the Engineering department (dept_id = 10).

σ⋈π
Selection (Restrict)
ex-begin-rename-attr
Beginner

Rename a column

Rename Students.name to student_name, then list distinct student_name values.

ρπ
Attribute Rename
ex-inter-theta-join
Intermediate

Explicit join condition

Match employees to departments using an explicit join on dept_id (theta join), then project name and dept_name.

⋈_θπ
Theta Join (Conditional Join)
ex-inter-cartesian
Intermediate

Full cross product

List every combination of employee name and department name using Cartesian product (expect four rows).

⨯π
Cartesian Product (Cross Join)
ex-inter-union
Intermediate

All people names

Build the set of distinct names appearing in either Students or Professors (one column: name).

∪π
Set Union
ex-inter-intersection
Intermediate

Double enrollees

Find student_id values enrolled in both course 101 and course 102.

∩σπ
Set Intersection
ex-inter-difference
Intermediate

Everyone but independents

List student_id values enrolled in at least one course, excluding those enrolled only in course 999 (Independent Study).

−σπ
Set Difference
ex-inter-left-join
Intermediate

Students without majors

Show every student_id with their major_name, including students with no major (NULL major_name).

⟕π
Left Outer Join
ex-adv-right-join
Advanced

Right-sided coverage

Using a right outer join, list student_id and major_name for students matched to a major (unmatched left rows dropped).

⟖π
Right Outer Join
ex-adv-full-join
Advanced

Full student–major picture

List every student_id with major_name, including students without majors (use full outer join).

⟗π
Full Outer Join
ex-adv-division
Advanced

Completed course 101

Find student_id values who are enrolled in course 101. Use division with Enrolled and a one-row course relation for course 101.

÷σπ
Relational Division
ex-adv-cs-majors
Advanced

Computer Science majors

List names of students majoring in Computer Science (major_id 10). Join Students and Majors, filter, then project name.

⋈σπ
Natural Join
ex-adv-credits-sum-filter
Advanced

Heavy course load

Find student_id values enrolled in at least one course with credits ≥ 4. Join Enrolled and Courses, filter, project student_id distinct.

⋈σπ
Natural Join