You can use SQL’s DELETE FROM command to delete records in the MySQL datasheet.
You can do it in the mysql> Execute the command at a command prompt or in a PHP script.
Grammar ¶
The following is the general syntax for the SQL DELETE statement to delete data from the MySQL data table:
DELETE FROM table_name [WHERE Clause]
-
If no WHERE clause is specified, all records in the MySQL table are deleted.
-
You can specify any condition in the WHERE clause
-
You can delete records in a single table at once.
The WHERE clause is very useful when you want to delete a specified record in a data table.
Delete data from the command line ¶
Here we will use the WHERE clause in the SQL DELETE command to delete the data selected by the MySQL data table runoob_tbl.
Example ¶
The following instance will be deleted runoob_tbl In the table runoob_id A record of 3:
DELETE statement:
mysql>useRUNOOB;Databasechangedmysql>DELETEFROMrunoob_tblWHERErunoob_id=3;QueryOK,1rowaffected(0.23sec)
Use PHP scripts to delete data ¶
PHP usage mysqli_query() Function to execute the SQL statement, you can use it in the SQL DELETE command or not WHERE Clause.
This function is similar to the mysql> The command executes the SQL command with the same effect.
Example ¶
The following PHP instances will be deleted runoob_tbl In the table runoob_id A record of 3:
MySQL DELETE clause test: