MySQL DELETE

The DELETE FROM statement is used to delete data from a database table.

Syntax:
DELETE FROM tableName
WHERE someColumn = someValue
Example:

Earlier in the tutorial, we created a table named "Employee". Here is how it looks:

FirstNameLastNameSalary
AlexRodriguez10000
AnnaWeston5000

The following example deletes the records in the "Employee" table where LastName='Rodriguez':

Example:
<?php
// Database connection establishment
    $con=mysqli_connect("example.com","alex","qwerty","db_name");
    
// Check connection
    if (mysqli_connect_errno($con)) {
    echo "MySQL database connection failed: " . mysqli_connect_error();
    }

    mysqli_query($con,"DELETE FROM employee WHERE LastName=`Rodriguez` ");
?>

Once deleted, the table will look like this:

FirstNameLastNameSalary
AnnaWeston5000

Courses
Subscribe Updates via Email

Join 49,000+ W3schools lovers and get all the latest tutorials, programs, algorithms in your inbox.