0
0
MySQLquery~20 mins

DELETE with WHERE clause in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DELETE Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output after DELETE with a simple WHERE?

Given a table Employees with rows:

id | name    | department
1  | Alice   | Sales
2  | Bob     | HR
3  | Charlie | Sales
4  | Diana   | IT

What rows remain after running this query?

DELETE FROM Employees WHERE department = 'Sales';
MySQL
SELECT * FROM Employees;
A[]
B[{"id":2,"name":"Bob","department":"HR"},{"id":4,"name":"Diana","department":"IT"}]
C[{"id":1,"name":"Alice","department":"Sales"},{"id":2,"name":"Bob","department":"HR"},{"id":3,"name":"Charlie","department":"Sales"},{"id":4,"name":"Diana","department":"IT"}]
D[{"id":1,"name":"Alice","department":"Sales"},{"id":3,"name":"Charlie","department":"Sales"}]
Attempts:
2 left
💡 Hint

DELETE removes rows matching the WHERE condition.

🧠 Conceptual
intermediate
1:30remaining
Which DELETE statement removes only one specific row?

Which DELETE query will remove only the employee with id = 3 from the Employees table?

ADELETE Employees WHERE id = 3;
BDELETE FROM Employees WHERE department = 'Sales';
CDELETE FROM Employees;
DDELETE FROM Employees WHERE id = 3;
Attempts:
2 left
💡 Hint

Use WHERE to target a specific row by id.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in this DELETE query

What is wrong with this DELETE statement?

DELETE Employees WHERE id = 5;
ATable name should be in quotes
BWHERE clause cannot be used with DELETE
CMissing FROM keyword after DELETE
DDELETE cannot delete by id
Attempts:
2 left
💡 Hint

Check the correct DELETE syntax.

optimization
advanced
2:00remaining
Which DELETE query is more efficient for removing multiple rows?

You want to delete employees with ids 2, 4, and 6. Which query is best?

ADELETE FROM Employees WHERE id IN (2, 4, 6);
BDELETE FROM Employees WHERE id BETWEEN 2 AND 6;
CDELETE FROM Employees WHERE id = 2 OR id = 4 OR id = 6;
DDELETE FROM Employees WHERE id > 1 AND id < 7;
Attempts:
2 left
💡 Hint

Use concise syntax for multiple values.

🔧 Debug
expert
2:30remaining
Why does this DELETE query delete all rows unexpectedly?

Given this query:

DELETE FROM Employees WHERE department = 'Marketing' OR 1=1;

Why does it delete all rows?

ABecause 1=1 is always true, so WHERE condition matches all rows
BBecause DELETE ignores WHERE clause
CBecause 'Marketing' is a reserved keyword
DBecause OR is not allowed in WHERE clause
Attempts:
2 left
💡 Hint

Think about how OR conditions work in WHERE.