0
0
SQLquery~20 mins

DELETE with WHERE condition in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DELETE Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What rows remain after DELETE with WHERE?
Given the table Employees with columns id, name, and department, and these rows:

1, 'Alice', 'Sales'
2, 'Bob', 'HR'
3, 'Charlie', 'Sales'
4, 'Diana', 'IT'

What rows remain after running:

DELETE FROM Employees WHERE department = 'Sales';
SQL
DELETE FROM Employees WHERE department = 'Sales';
A[]
B[{id: 1, name: 'Alice', department: 'Sales'}, {id: 3, name: 'Charlie', department: 'Sales'}]
C[{id: 2, name: 'Bob', department: 'HR'}, {id: 3, name: 'Charlie', department: 'Sales'}, {id: 4, name: 'Diana', department: 'IT'}]
D[{id: 2, name: 'Bob', department: 'HR'}, {id: 4, name: 'Diana', department: 'IT'}]
Attempts:
2 left
💡 Hint
DELETE removes rows matching the WHERE condition.
📝 Syntax
intermediate
2:00remaining
Which DELETE statement is syntactically correct?
Choose the correct DELETE statement that removes rows where age is less than 30 from the Users table.
ADELETE FROM Users WHERE age < 30;
BDELETE Users WHERE age < 30;
CDELETE * FROM Users WHERE age < 30;
DDELETE FROM Users WHERE age >= 30;
Attempts:
2 left
💡 Hint
DELETE requires FROM keyword and correct comparison operators.
optimization
advanced
2:00remaining
How to optimize DELETE with large data and WHERE condition?
You want to delete millions of rows from Orders where status = 'cancelled'. Which approach is best to avoid long locks and improve performance?
ADROP TABLE Orders; CREATE TABLE Orders AS SELECT * FROM Orders WHERE status != 'cancelled';
BDELETE FROM Orders WHERE status = 'cancelled';
CDELETE FROM Orders WHERE status = 'cancelled' LIMIT 10000; (repeat until done)
DUPDATE Orders SET status = NULL WHERE status = 'cancelled';
Attempts:
2 left
💡 Hint
Deleting in smaller batches reduces lock time.
🔧 Debug
advanced
2:00remaining
Why does this DELETE statement fail with syntax error?
Given this SQL:

DELETE FROM Customers WHERE name = 'John' AND;

What is the cause of the syntax error?
SQL
DELETE FROM Customers WHERE name = 'John' AND;
AThe DELETE statement requires a semicolon before WHERE.
BThe WHERE clause ends with AND without a condition after it.
CThe table name Customers is reserved and cannot be used.
DThe string 'John' must be enclosed in double quotes.
Attempts:
2 left
💡 Hint
Check the WHERE clause syntax carefully.
🧠 Conceptual
expert
2:00remaining
What happens if DELETE is run without WHERE?
Consider the table Products with 1000 rows. What is the effect of running:

DELETE FROM Products;

Choose the correct statement.
SQL
DELETE FROM Products;
AAll 1000 rows are deleted, leaving an empty table.
BThe command deletes no rows because WHERE is missing.
CThe table structure is deleted along with data.
DOnly the first row is deleted by default.
Attempts:
2 left
💡 Hint
Think about what DELETE does without a filter.