PHP MySQL DELETE Query
DELETE statement is used to delete/remove one or more records from a table.
The basic DELETE syntax is as follows:
DELETE FROM table_name [WHERE some_condition_is_true] [LIMIT rows]Notice that no column specification is used in the DELETE command—when you use DELETE, the entire record is removed. When updating a table without specifying a condition caused an update of all records. You must be similarly careful when using DELETE.
The following statement will remove all the records from the student table:
DELETE FROM student;
Conditional DELETE:
A conditional DELETE statement, just like a conditional SELECT or UPDATE statement, means you are using WHERE clauses to match specific records. You have the full range of comparison and logical operators available to you, so you can pick and choose which records you want to delete.
Example:
DELETE FROM STUDENT WHERE RollNumber = 2;
Caution: Like UPDATE statement, we need to be careful to include the WHERE clause while using a DELETE statement to delete records in a table. Otherwise, all the records in the table will get deleted.