MySQL Delete Data

  • Delete query is used to delete desired rows from table.

Syntax

Syntax1
  • To delete all the rows from table:
  • DELETE FROM tableName;
  • It will delete all the rows that satisfy the condition:
Syntax2
DELETE FROM tableName WHERE conditions;

Example

We have following table with us-

idnamesalarycontact
1John250007777777
2Peter400009999999
  • Now we have to delete data from the above table using following code:
<!DOCTYPE html>

<html>

<body>

<?php

$connect=mysqli_connect("localhost","root","","firstdb");

$query="DELETE FROM employee WHERE name='peter'";

$result=mysqli_query($connect,$query);

?>

</body>

</html>

Output

After running the program, the table will appear as following:

idnamesalarycontact
1John250007777777
  • Above program will delete the row/rows in which have 'peter' as the value of column 'name'.