
👉What is the MySQL DELETE Query?
MySQL DELETE Query :The DELETE statement in MySQL is used to remove one or more rows from a table. It is useful for deleting obsolete or temporary data from a database. However, once a row is deleted, it cannot be recovered, so it’s recommended to back up your data before executing a delete command.
👉Basic Syntax of MySQL DELETE Query
sql
DELETE FROM `table_name` [WHERE condition];
- DELETE FROM table_name – Specifies the table from which rows should be deleted.
- [WHERE condition] – Filters the rows to be deleted. If omitted, all rows in the table will be deleted.
⚠️ Be careful when running a DELETE statement without a WHERE clause, as it will remove all data from the table!
👉Example: Deleting a Row in MySQL
Example: Deleting a Row in MySQL
MySQL DELETE Query : Before deleting data, let’s insert sample records into a movies table:
sql
INSERT INTO `movies` (`title`, `director`, `year_released`, `category_id`)
VALUES (‘The Great Dictator’, ‘Charlie Chaplin’, 1920, 7);
Now, if we want to remove this movie from our database:
sql
DELETE FROM `movies` WHERE `movie_id` = 18;
This command will delete the row where movie_id is 18.
👉Deleting Multiple Rows in MySQL
To delete multiple rows, use the IN clause:
sql
DELETE FROM `movies` WHERE `movie_id` IN (20, 21);
This deletes the records with movie_id 20 and 21.
👉Checking Data After Deletion
To confirm the deletion, run:
sql
SELECT * FROM `movies`;
The deleted rows will no longer appear in the result set.
👉Key Notes on DELETE in MySQL
âś… The DELETE command removes entire rows, not individual columns.
âś… The WHERE clause is essential to limit the number of deleted rows.
âś… Once a row is deleted, it cannot be recovered unless you have a backup.
👉Summary
- The MySQL DELETE command removes unwanted rows from a table.
- The WHERE clause helps limit which rows are deleted.
- Always back up your database before running DELETE commands.
By following best practices, you can safely manage data deletion in MySQL.