SQL QuestSQL Interview Questions › Querying Basics

Delete the Empty Accounts

EasyFreeQuerying Basics

Housekeeping: accounts that signed up and never ordered anything are cluttering the customer table.

Delete every customer whose total_orders is 0, then show a single column remaining with the count of customers left.

DELETE FROM table WHERE ... removes whole rows — you never name columns, because you are not deleting a value, you are deleting a record. And the same warning as UPDATE, only worse: DELETE FROM customers with no WHERE empties the table.

A habit that will save you one day: run the WHERE as a SELECT first. If SELECT * FROM customers WHERE total_orders = 0 returns what you expect, the DELETE will too.

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

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: remaining = 13

Hint

DELETE FROM customers WHERE total_orders = 0; then SELECT COUNT(*) AS remaining FROM customers.

Concepts

DELETE DML WHERE

Practise the topic: SQL practice questions

Related questions

Your First QueryEasy · FreePick Your ColumnsEasy · FreeFilter with WHEREEasy · FreeComparison OperatorsEasy · FreeMultiple Conditions (AND / OR)Easy · FreeThe IN OperatorEasy · 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