BeginnerAbout 15 min

    Relational Algebra & Joins

    Read the full article on Substack

    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.

    users (A)orders (B)match
    users (A)
    IDName
    1Alice
    2Bob
    3Eve
    orders (B)
    U_IDItem
    1Pen
    2Mug
    9Hat
    result
    IDNameItem
    1AlicePen
    2BobMug

    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

    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 here
    6 pieces left to place

    Quiz

    21 questions
    Question 1 of 21
    Score: 0

    If 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.

    Keep going