
- 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
How to delete a single value from a MySQL table with duplicate records?
Use DELETE to delete records, but if you have multiple duplicate records, then limit the deletion using MySQL LIMIT as in the below syntax −
Syntax
delete from yourTableName where yourColumnName=yourValue limit 1;
Let us first create a table −
mysql> create table DemoTable -> ( -> Amount int -> ); Query OK, 0 rows affected (1.38 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(100); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.59 sec) mysql> insert into DemoTable values(70); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(90); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Amount | +--------+ | 50 | | 100 | | 50 | | 70 | | 90 | | 50 | +--------+ 6 rows in set (0.00 sec)
Here is the query to delete a single value from a table −
mysql> delete from DemoTable where Amount=50 limit 1; Query OK, 1 row affected (0.39 sec)
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Amount | +--------+ | 100 | | 50 | | 70 | | 90 | | 50 | +--------+ 5 rows in set (0.00 sec)
- Related Articles
- Delete records from a MySQL table with IN() in a single query
- How to delete all the duplicate records in a MySQL table?
- Delete all records from a table in MySQL?
- Delete all the records from a MySQL table?
- How can we delete a single row from a MySQL table?
- How to remove Duplicate Records except a single record in MySQL?
- Delete records from a MySQL table by excluding non-deleted records using NOT IN
- How to delete the duplicate values stored in reverse order from MySQL table?
- MySQL query to display the count of distinct records from a column with duplicate records
- Return only a single row from duplicate rows with MySQL
- How to delete a column from a table in MySQL?
- How to delete all records from a table in Oracle using JDBC API?
- A single MySQL query to insert records (not all) in the second table from the first table
- Display an error while inserting duplicate records in a MySQL table
- Display selected records from a MySQL table with IN() operator

Advertisements