DELETE JOIN — SQL Technical Interview Questions & Answers

DELETE JOIN

DELETE JOIN

  • MySQL allows DELETE s FROM students s JOIN marks m ON s.roll = m.roll WHERE m.score = 0; delete students who have a zero paper. Multi-table DELETE needs the alias after DELETE.
  • Safer: SELECT first, then delete by PK list. FKs still apply.
  • Trap: DELETE FROM students JOIN … with SQL Server syntax. MySQL wants DELETE alias FROM … JOIN.
  • On the example next to this theory: DELETE JOIN — dELETE removes matching rows. TRUNCATE clears a whole table faster (MySQL).

Technical Interview Tip: DELETE s FROM students s JOIN marks m ON … WHERE …

Code Examples for DELETE JOIN

DELETE JOIN — sample query

CREATE TABLE tags (id INTEGER PRIMARY KEY, label TEXT);
INSERT INTO tags VALUES (1, 'old'), (2, 'keep');
DELETE FROM tags WHERE label = 'old';
SELECT * FROM tags;

DELETE JOIN — dELETE removes matching rows. TRUNCATE clears a whole table faster (MySQL).

How to Explain DELETE JOIN to an Interviewer

MySQL multi-table DELETE shape?

DELETE s FROM students s JOIN …