
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 records from a MySQL table with IN() in a single query
Let us create a table −
mysql> create table DemoTable1922 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1922(StudentName) values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('Robert'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1922(StudentName) values('Mike'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1922;
This will produce the following output −
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Robert | | 3 | David | | 4 | Mike | +-----------+-------------+ 4 rows in set (0.00 sec)
Here is the query to delete records from a table with IN() −
mysql> delete from DemoTable1922 where StudentId IN(1,2,3,4); Query OK, 4 rows affected (0.00 sec)
Let us check table records once again −
mysql> select * from DemoTable1922;
This will produce the following output −
Empty set (0.00 sec)
- Related Questions & Answers
- How to delete a single value from a MySQL table with duplicate records?
- Delete all records from a table in MySQL?
- Delete all the records from a MySQL table?
- A single MySQL query to insert records (not all) in the second table from the first table
- MySQL query to find alternative records from a table
- MySQL update multiple records in a single query?
- How can we delete a single row from a MySQL table?
- Insert all the values in a table with a single MySQL query separating records by comma
- Delete records from a MySQL table by excluding non-deleted records using NOT IN
- MySQL query to fetch the latest date from a table with date records
- Insert multiple values in a temporary table with a single MySQL query?
- Selecting a value in custom order from another column in a MySQL table with a single query
- Delete selective multiple records using MySQL DELETE query
- Display selected records from a MySQL table with IN() operator
- MySQL SELECT from two tables with a single query
Advertisements