SQL QuestSQL Interview Questions › Joins

JOIN with a Filter

EasyFreeQuerying BasicsJoins

Merchandising wants the electronics orders only, with the customer attached to each one.

Join orders to customers and show name, membership, product, total for orders where category is 'Electronics'. Order by total descending, then order_id.

The new idea: once two tables are joined, WHERE can filter on either one of them. You joined on customers but filtered on an orders column, and SQL doesn't care which side a column came from — after the join it's all one row. Table aliases (o, c) are what keep that readable once column names start repeating.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

orders

order_idcustomer_idproductcategoryquantitypricetotalorder_datecountrystatus
11Laptop ProElectronics11299.991299.992024-01-15USAcompleted
22Wireless MouseElectronics249.9999.982024-01-16Canadacompleted
33Office ChairFurniture1349.99349.992024-01-17USAcompleted

customers

customer_idnameemailsignup_datemembershiptotal_orders
1John Smithjohn.smith@email.com2023-01-15Gold15
2Emma Wilsonemma.wilson@email.com2023-03-20Silver8
3Michael Brownmichael.brown@email.com2023-02-10Gold12

Expected output: 23 rows, each with the customer's name and membership attached

Hint

The hint for this one spells out most of the query, so it stays in the editor. Reach for SELECT, JOIN, WHERE, and open the hint there if you stall.

Concepts

SELECT JOIN WHERE

Practise the topic: SQL practice questions · JOIN practice

In these company practice sets

Stripe · DoorDash · LinkedIn

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Your First JOINEasy · FreeLEFT JOIN: Watch the NULLs AppearEasy · FreeCounting Across a JOINEasy · FreeTransaction Share by Merchant CategoryEasy · FreeSignup-Month Cohort SpendEasy · FreeCard Spend by CountryEasy · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test