
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Delete a record with tablename.columnname= value in MySQL
To delete a record in the required way, the syntax is as follows −
delete from yourTableName where yourTableName .yourColumnName=yourValue;
Let us first create a table −
mysql> create table DemoTable ( StudentName varchar(100), StudentAge int ); Query OK, 0 rows affected (0.81 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris',21); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Robert',20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('David',22); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Mike',24); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Sam',19); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+------------+ | StudentName | StudentAge | +-------------+------------+ | Chris | 21 | | Robert | 20 | | David | 22 | | Mike | 24 | | Sam | 19 | +-------------+------------+ 5 rows in set (0.00 sec)
Here’s how you can use tablename.columnname= value to get a value and delete it in MySQL −
mysql> delete from DemoTable where DemoTable.StudentName='Robert'; Query OK, 1 row affected (0.12 sec)
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+------------+ | StudentName | StudentAge | +-------------+------------+ | Chris | 21 | | David | 22 | | Mike | 24 | | Sam | 19 | +-------------+------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to delete a record with the lowest ID?
- Replace a specific duplicate record with a new value in MySQL
- MySQL CONCAT a specific column value with the corresponding record
- Delete a specific record on the basis of EmployeeId in MySQL
- Search record with a specific value in MySQL using LIKE or REGEXP?
- How to select record except the lower value record against a specific value in MySQL?
- How to delete last record (on condition) from a table in MySQL?
- How can you delete a record from a table using MySQL in Python?
- Delete a specific record from a MySQL table by using AND in WHERE clause
- Insert record in a MySQL table with Java
- How to delete fields with values more than a particular value in MySQL?
- Display record with today and tomorrow’s date from a column with date record in MySQL
- How to delete a single value from a MySQL table with duplicate records?
- How to delete a single record in Laravel 5?
- Delete Leaves With a Given Value in C++

Advertisements