Relational Algebra & Joins
5 min read.
Visualize the mathematical foundations of SQL: Projections, Selections, and different types of Joins.
Think of it this way: Relational Algebra is the blueprint for SQL. Projection is slicing a spreadsheet vertically (keeping only some columns). Selection is slicing it horizontally (keeping only some rows). A Join is stitching two spreadsheets together based on matching IDs.
| ID | Name |
|---|---|
| 1 | Alice |
| 2 | Bob |
| 3 | Eve |
| U_ID | Item |
|---|---|
| 1 | Pen |
| 2 | Mug |
| 9 | Hat |
| ID | Name | Item |
|---|---|---|
| 1 | Alice | Pen |
| 2 | Bob | Mug |
An inner join keeps only rows that match on both sides. Eve has no order and the Hat has no user, so both drop out.
Check your understanding
Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.
σ, π or ⋈?
Sort each description into the relational operator it describes.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
σ Selection
Drop items hereπ Projection
Drop items here⋈ Join
Drop items hereQuiz
21 questionsIf Table A has 5 rows and Table B has 4 rows, and you perform a CROSS JOIN (Cartesian Product), how many rows will be in the result set?
Done with this lesson?
Sign in free to keep your progress, streak and quiz scores.