
- 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 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 Articles
- 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
- Insert all the values in a table with a single MySQL query separating records by comma
- MySQL update multiple records in a single query?
- Delete records from a MySQL table by excluding non-deleted records using NOT IN
- MySQL query to find alternative records from a table
- How can we delete a single row from a MySQL table?
- Selecting a value in custom order from another column in a MySQL table with a single query
- Insert multiple values in a temporary table with a single MySQL query?
- MySQL query to fetch the latest date from a table with date records
- Delete selective multiple records using MySQL DELETE query
- Display selected records from a MySQL table with IN() operator
- MySQL query to display records from a table filtered using LIKE with multiple words?

Advertisements