{"id":3930,"date":"2025-06-06T20:40:24","date_gmt":"2025-06-06T20:40:24","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3930"},"modified":"2026-09-26T13:14:58","modified_gmt":"2026-09-26T07:44:58","slug":"sql-delete","status":"publish","type":"post","link":"https:\/\/w3buddy.com\/blog\/sql-delete\/","title":{"rendered":"SQL DELETE"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The <code>DELETE<\/code> statement is used to <strong>remove one or more rows<\/strong> from a table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Basic Syntax<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>DELETE FROM table_name\nWHERE condition;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u26a0\ufe0f Always use a <code>WHERE<\/code> clause to avoid deleting everything!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Examples<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Delete a specific employee\nDELETE FROM employees\nWHERE employee_id = 101;\n\n-- Delete all employees from the IT department\nDELETE FROM employees\nWHERE department = 'IT';<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 Delete All Rows (Be Cautious!)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Delete all rows (but keep the table)\nDELETE FROM employees;\n\n-- Oracle tip: Use TRUNCATE for faster delete (no WHERE allowed)\nTRUNCATE TABLE employees;<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd39 With Subqueries<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Delete employees who are not assigned to any department\nDELETE FROM employees\nWHERE department_id NOT IN (\n  SELECT id FROM departments\n);<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Quick Recap<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Action<\/th><th>Syntax Example<\/th><\/tr><\/thead><tbody><tr><td>Delete with condition<\/td><td><code>DELETE FROM table WHERE ...<\/code><\/td><\/tr><tr><td>Delete all rows<\/td><td><code>DELETE FROM table;<\/code><\/td><\/tr><tr><td>Fast delete (Oracle)<\/td><td><code>TRUNCATE TABLE table_name;<\/code><\/td><\/tr><tr><td>Delete using subquery<\/td><td><code>DELETE WHERE col IN (SELECT ...)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u2705 Use <code>DELETE<\/code> to clean up data\u2014carefully!<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The DELETE statement is used to remove one or more rows from a table. \ud83d\udd39 Basic Syntax \u26a0\ufe0f Always use a WHERE clause to avoid deleting everything! \ud83d\udd39 Examples \ud83d\udd39 Delete All Rows (Be Cautious!) \ud83d\udd39 With Subqueries \ud83e\udde0 Quick Recap Action Syntax Example Delete with condition DELETE FROM table WHERE &#8230; Delete all rows [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"googlesitekit_rrm_CAowu461DA:productID":"","footnotes":""},"categories":[1225,979],"tags":[],"class_list":["post-3930","post","type-post","status-publish","format-standard","hentry","category-database","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/comments?post=3930"}],"version-history":[{"count":2,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3930\/revisions"}],"predecessor-version":[{"id":4036,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/posts\/3930\/revisions\/4036"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/tags?post=3930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}