MySQL DELETE Statement

The DELETE statement in MySQL is used to delete one or more rows from a table. The basic syntax of the DELETE statement is as follows:

DELETE FROM table_name WHERE condition;

Here, table_name is the name of the table that we want to delete rows from. condition is a condition that determines which rows to delete.

For example, let’s say we have a table named employees with columns id, name, age, and salary. To delete an employee with id = 1, we can use the following SQL query:

DELETE FROM employees WHERE id = 1;

If we want to delete all rows in the table, we can omit the WHERE clause:

DELETE FROM employees;

Note that deleting all rows in a table can be dangerous and should be avoided unless we really want to delete all rows.

We can also use the LIMIT clause to limit the number of rows that are deleted. For example, to delete the first 10 employees whose age is greater than or equal to 30, we can use the following SQL query:

DELETE FROM employees WHERE age >= 30 LIMIT 10;

It is important to be careful when using the DELETE statement, as it permanently removes data from the table. We should always make sure that we have a backup of the data or that we are absolutely sure that we want to delete the data before using the DELETE statement.

Wordpress Social Share Plugin powered by Ultimatelysocial
Wordpress Social Share Plugin powered by Ultimatelysocial