CodeEraFree roadmap

SQL Practice / DELETE, DROP and TRUNCATE

SQL DELETE, DROP and TRUNCATE: practice questions with answers

9 questions with solved queries and real output. Outputs checked on MariaDB 10.11 (MySQL-compatible) on 23 November 2026.

Three commands remove things, and they are very different:

  • DELETE removes rows, usually with a WHERE condition. Without WHERE it deletes every row. It can usually be rolled back inside a transaction.
  • TRUNCATE TABLE removes all rows quickly and keeps the table. It cannot be used with a condition.
  • DROP TABLE removes the whole table: its rows, its structure and its constraints.

Each question below starts from the original employees table, so you can try them one at a time. Take a copy of your data before you practise on a real database.

DELETE FROM table_name WHERE condition;
TRUNCATE TABLE table_name;
DROP TABLE table_name;

These questions use the employees table (30 rows). Create it first with the copy-and-paste setup script. Here is the data, so you can check your answers by eye.

See the employees table

Table: employees

emp_nofirst_namelast_namesalarybirth_dategenderjoining_datedepartment
1001JamesBond453001998-01-19M2020-11-29Marketing
1002RobertLee694101998-09-02M2019-12-26IT
1003MaryWood395181997-11-07F2019-09-12Business Development
1004JohnCole362641999-02-01M2021-04-14HR
1005JenniferGill489411996-06-05F2019-06-28Marketing
1006MichaelWatts238001999-04-16M2022-06-09HR
1007DavidMills394001998-04-26M2021-10-17IT
1008WilliamHill263921999-10-21M2019-09-30Business Development
1009LindaPotter552311998-01-24F2021-08-07Finance
1010RichardMartin256001996-08-07M2021-03-23IT
1011SusanHall541521999-12-27F2020-08-07Finance
1012JosephTurner605561997-05-13M2019-09-02Marketing
1013MaryGill582461999-01-21F2021-04-30Business Development
1014ThomasRyan236761996-10-12M2022-03-02IT
1015CharlesWilliams572262000-01-29M2019-11-05NULL
1016JessicaClarkNULL2000-01-25F2020-01-24IT
1017NancyParker669001996-10-24F2022-01-09Finance
1018BettyBarker352881998-11-13F2019-12-26HR
1019ChristopherGibson593411998-04-23M2019-05-02Marketing
1020DanielElliott440121999-01-21M2023-01-08IT
1021DavidMillsNULL1998-01-24M2019-12-26IT
1022SarahHarrison446921996-03-20F2020-05-03Finance
1023MatthewHill413651998-05-16M2019-05-23IT
1024AnthonyMiller567941996-06-30M2019-02-28Business Development
1025MarkWood651201998-10-29M2020-07-30Business Development
1026ElizabethWalker470301998-08-11F2021-06-18NULL
1027BarbaraAndersonNULL1999-12-27F2021-03-14HR
1028JessicaClark638361998-01-24F2021-05-23IT
1029NancyCole636692000-01-26F2019-12-26Finance
1030JoeBrooks440001999-08-05M2021-03-09Business Development

You can do these in any order. Each answer below was run on a fresh copy of the original table, so earlier queries do not change later results.

How to use this page: read a question, write your own query, then open "Show the answer" and compare. Trying first is what makes it stick.

Question 1Delete employees hired after '2022-01-01'.

Show the answer and the output
DELETE FROM employees WHERE joining_date > '2022-01-01';

Output

Query OK, 4 rows affected.

Then check with SELECT COUNT(*) AS remaining FROM employees

remaining
26

Question 2Delete employees whose birth date is in the year 2000 or later.

Show the answer and the output
DELETE FROM employees WHERE YEAR(birth_date) >= 2000;

Output

Query OK, 3 rows affected.

Then check with SELECT COUNT(*) AS remaining FROM employees

remaining
27

Question 3Delete employees with a NULL salary.

Show the answer and the output
DELETE FROM employees WHERE salary IS NULL;

Output

Query OK, 3 rows affected.

Then check with SELECT COUNT(*) AS remaining FROM employees

remaining
27

Use IS NULL. salary = NULL would delete nothing.

Question 4Delete employees who are in the 'IT' department and joined before '2020-01-01'.

Show the answer and the output
DELETE FROM employees
WHERE department = 'IT' AND joining_date < '2020-01-01';

Output

Query OK, 3 rows affected.

Then check with SELECT COUNT(*) AS remaining FROM employees

remaining
27

Question 5Delete employees with a birth date in January.

Show the answer and the output
DELETE FROM employees WHERE MONTH(birth_date) = 1;

Output

Query OK, 9 rows affected.

Then check with SELECT COUNT(*) AS remaining FROM employees

remaining
21

Question 6Delete the employee with the highest salary.

Show the answer and the output
DELETE FROM employees
WHERE salary = (SELECT max_salary FROM (SELECT MAX(salary) AS max_salary FROM employees) AS t);

Output

Query OK, 1 row affected.

Then check with SELECT COUNT(*) AS remaining FROM employees

remaining
29

MySQL does not allow a DELETE to read from the same table in a subquery (error 1093). Wrapping the subquery one level deeper, as a derived table, avoids that, and it works in other databases too.

Different from the PDF: The PDF answer had a missing space (employeesWHERE) and reads the same table directly, which MySQL rejects. The derived table form works.

Question 7Delete the oldest employee in the 'HR' department.

Show the answer and the output
DELETE FROM employees
WHERE department = 'HR'
ORDER BY birth_date
LIMIT 1;

Output

Query OK, 1 row affected.

Then check with SELECT COUNT(*) AS remaining FROM employees

remaining
29

DELETE ... ORDER BY ... LIMIT is MySQL syntax. The oldest person has the earliest birth date.

Question 8Truncate the employees table.

Show the answer and the output
TRUNCATE TABLE employees;

Output

Query OK.

Then check with SELECT COUNT(*) AS remaining FROM employees

remaining
0

All rows are gone, but the table (its columns and keys) is still there.

Question 9Drop the employees table.

Show the answer and the output
DROP TABLE employees;

Output

Query OK.

Then check with SHOW TABLES LIKE 'employees'

Empty set: the query ran and no rows matched.

The table itself is gone. Running SELECT * FROM employees now gives an error.

Want these as PDFs? Download the question PDF or the answer PDF to practise offline.