Courses Job Ready Fresher Training AI for Class 7 to 12 Corporate Training Placements Tutorials
Free Learning Resources

IT Tutorials & Interview Prep

Free guides, interview Q&As, and job responsibility breakdowns — curated by industry veterans to help you crack MNC interviews

109+
Tutorial Articles
9
Topic Categories
100%
Free to Read
← Back to PHP

Deleting Data in MySQL

PHP Last Updated: Oct 17, 2025

Deleting Data in MySQL

To delete data in the MySQL database, we can use the DELETE statement.

Query:

DELETE FROM table_nameWHERE some_column = some_value

Let's assume we want to delete the second employee "Rohan" from the "Employees" Table. We will use the DELETE clause with the WHERE clause to specify which data is being deleted.

employeeIDfirstnamelastnameemailjoining_date
1HarryBhaiharrybhai@bhai.com2025-10-17 14:54:58
2RohanDasrohanbhai@bhai.com2025-10-18 15:44:51

Example:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "cwhDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
 die("Connection failed: " . $conn->connect_error);
}

// sql to delete a record
$sql = "DELETE FROM Employees WHERE firstname='Rohan'";

if ($conn->query($sql) === TRUE) {
 echo "Record deleted successfully";
} else {
 echo "Error deleting record: " . $conn->error;
}

$conn->close();
?>

After deleting, this is how our table will look:

employeeIDfirstnamelastnameemailjoining_date
1HarryBhaiharrybhai@bhai.com2025-10-17 14:54:58
Want to practice these scenarios in a real IT environment? Our 45-Day Internship Program gives you hands-on experience with Active Directory, Ticketing Tools, and Networking.
Join the Internship →