

- 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
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 Questions & Answers
- Display first selected row in MySQL?
- Get the size of selected rows in MySQL
- Inserting multiple rows in MySQL?
- Concatenate data from multiple rows using GROUP_CONCAT() in MySQL?
- Select rows from a MySQL table and display using IN()
- Count(*) rows from multiple tables in MySQL?
- How to update multiple rows using single WHERE clause in MySQL?
- Display selected records from a MySQL table with IN() operator
- MySQL query to select multiple rows effectively?
- 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
- Count multiple rows and display the result in different columns (and a single row) with MySQL
- Update multiple rows in a single column in MySQL?
- How to order MySQL rows by multiple columns?
Advertisements