| Algebra | SQL |
|---|---|
r × s | SELECT * FROM r CROSS JOIN s |
r.a | r.a |
ρ a (r) | r AS a |
- Before you run anything: how many tuples does
department × coursereturn? σ instructor.id = teaches.id (instructor × teaches)π name, course_id (σ instructor.id = teaches.id (instructor × teaches))- Which departments share a building? Write the SQL for:
text
π a.dept_name, b.dept_name (σ a.building = b.building ∧ a.dept_name < b.dept_name (ρ a (department) × ρ b (department)))The condition a.dept_name < b.dept_name keeps each pair once, and removes a department paired with itself.