The Escuela

← Relational algebra: all 5 exercises

Databases · Free practice

Relational Algebra, Exercise 2: Self-join

Watch the worked solution by Dr. J. Ubaldo Quevedo, then practice as many times as you want: every click of New database gives you new data to work with.

1. Watch

The relations: employees(eid, name, salary, did, m_did) · projects(pid, description) · works_on(eid, pid, hours) · departments(did, location)

  • To compare two rows of the same table, give the table two names: e := employees and m := employees.
  • Join each employee e to their manager m with e.m_did = m.eid.
  • Then select e.salary > m.salary and project e.name.

2. Try it yourself

Practice as many times as you want. New database fills the tables with new employees, salaries and hours, and New question changes the details of the query. It's free, and you don't need an account.

Correct so far: 0