
- 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
Display multiple selected rows using MySQL IN()
Let us first create a table −
mysql> create table DemoTable1045 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100) )AUTO_INCREMENT=100; Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1045(FirstName) values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1045(FirstName) values('Chris'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1045(FirstName) values('Robert'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1045(FirstName) values('Mike'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1045(FirstName) values('Adam'); Query OK, 1 row affected (0.08 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1045;
This will produce the following output −
+-----+-----------+ | Id | FirstName | +-----+-----------+ | 100 | John | | 101 | Chris | | 102 | Robert | | 103 | Mike | | 104 | Adam | +-----+-----------+ 5 rows in set (0.00 sec)
Following is the MySQL query to display multiple selected rows −
mysql> select *from DemoTable1045 tbl where(tbl.Id, tbl.FirstName) IN ((101, 'Chris'), (102, 'Robert'), (104,'Adam'));
This will produce the following output −
+-----+-----------+ | Id | FirstName | +-----+-----------+ | 101 | Chris | | 102 | Robert | | 104 | Adam | +-----+-----------+ 3 rows in set (0.05 sec)
- Related Articles
- Display first selected row in MySQL?
- Concatenate data from multiple rows using GROUP_CONCAT() in MySQL?
- Get the size of selected rows in MySQL
- Inserting multiple rows in MySQL?
- Select rows from a MySQL table and display using IN()
- How to update multiple rows using single WHERE clause in MySQL?
- Count(*) rows from multiple tables in MySQL?
- Display selected records from a MySQL table with IN() operator
- Count multiple rows and display the result in different columns (and a single row) with MySQL
- Display selected checkboxes on another page using JavaScript?
- MySQL query to count rows in multiple tables
- Insert multiple rows in a single MySQL query
- Implement MySQL IN for 2 columns to display only selected records
- MySQL query to select multiple rows effectively?
- Update multiple rows in a single column in MySQL?

Advertisements