Excel to SQL · Lesson 8 of 12

VLOOKUP is a JOIN

In Excel, you'd reach for
fx=VLOOKUP(C2, Products!A:D, 3, FALSE) or =XLOOKUP

Orders only store a product_id. To see the product's name and price you'd VLOOKUP into the products sheet. In SQL you join the two tables on the column they share.

Read JOIN products p ON p.id = o.product_id as: "for each order, find the product whose id matches this order's product_id." The short letters (o, p) are nicknames so you don't type full table names everywhere.

SQL joins Venn diagram: INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL OUTER JOIN, each with its query
The four SQL joins as Venn diagrams, each with its query. Download · Save to Pinterest
Try itEdit the query, then Run
order_dateproductcategoryquantityunit_price
2026-01-01Desk LampOffice139
2026-01-01Desk LampOffice339
2026-01-01Standing DeskFurniture1449
2026-01-02Standing DeskFurniture2449
2026-01-02Desk LampOffice439
2026-01-02Ergo ChairFurniture2329
2026-01-03Notebook PackStationery112
2026-01-04Notebook PackStationery212
2026-01-04Monitor ArmOffice289
2026-01-04Noise-Cancel HeadsetElectronics2149

10 rows

Two differences from VLOOKUP, both in your favour. The join brings back as many columns as you like in one go, not one per formula. And there's no dragging a formula down 10,000 rows.

A plain JOIN drops rows that find no match (Excel would show #N/A). Use LEFT JOIN to keep them, with empty values where the match failed.

Your turn

Total revenue per product category: join orders to products and sum quantity * unit_price as revenue, highest first.

This page on one card

VLOOKUP is a JOIN: the Excel way (=VLOOKUP(C2) and the SQL query, side by side
VLOOKUP is a JOIN, on one card: the Excel way and the SQL. Download · Save to Pinterest
The practice data (7 tables)

See every column and sample rows