- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Delete selective multiple records using MySQL DELETE query
For selective multiple records, use MySQL IN(). To delete them, use MySQL DELETE. Let us first create a table −
mysql> create table DemoTable ( ClientId varchar(40), ClientName varchar(50) ); Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('CLI-101','Chris'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('CLI-110','Adam'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('CLI-220','Mike'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-120','Bob'); Query OK, 1 row affected (0.53 sec) mysql> insert into DemoTable values('CLI-240','Sam'); Query OK, 1 row affected (0.06 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------+------------+ | ClientId | ClientName | +----------+------------+ | CLI-101 | Chris | | CLI-110 | Adam | | CLI-220 | Mike | | CLI-120 | Bob | | CLI-240 | Sam | +----------+------------+ 5 rows in set (0.00 sec)
Here is the query to delete selective multiple records −
mysql> delete from DemoTable where ClientId IN('CLI-101','CLI-220','CLI-240'); Query OK, 3 rows affected (0.10 sec)
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+----------+------------+ | ClientId | ClientName | +----------+------------+ | CLI-110 | Adam | | CLI-120 | Bob | +----------+------------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL query to delete row
- Delete records from a MySQL table with IN() in a single query
- Delete records from a MySQL table by excluding non-deleted records using NOT IN
- Delete all records from a table in MySQL?
- Delete all the records from a MySQL table?
- Order records and delete n rows in MySQL
- Delete multiple entries from a MySQL table
- Implement DELETE query in MySQL stored procedure
- MySQL query to insert multiple records quickly
- Delete records where timestamp older than 5 minutes in MySQL?
- MySQL update multiple records in a single query?
- How to delete multiple documents in MongoDB using deleteMany()?
- How to delete all the duplicate records in a MySQL table?
- How can we delete multiple rows from a MySQL table?
- MySQL query to delete a record with the lowest ID?

Advertisements