

- 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
How to get multiple rows in a single MySQL query?
Let us first create a table −
mysql> create table DemoTable ( Id int, Name varchar(100) ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100,'Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(110,'David'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(120,'Robert'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(130,'Mike'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+--------+ | Id | Name | +------+--------+ | 100 | Chris | | 110 | David | | 120 | Robert | | 130 | Mike | +------+--------+ 4 rows in set (0.00 sec)
Following is the query to get multiple rows in a single MySQL query −
mysql> select *from DemoTable where Id IN(100,120,130):
This will produce the following output −
+------+--------+ | Id | Name | +------+--------+ | 100 | Chris | | 120 | Robert | | 130 | Mike | +------+--------+ 3 rows in set (0.02 sec)
- Related Questions & Answers
- How to obtain multiple rows in a single MySQL query?
- Insert multiple rows in a single MySQL query
- How to insert multiple rows with single MySQL query?
- Update multiple rows in a single MongoDB query?
- MySQL query to sort multiple columns together in a single query
- Multiple COUNT() for multiple conditions in a single MySQL query?
- Get multiple count in a single MySQL query for specific column values
- Implement multiple COUNT() in a single MySQL query
- Change multiple columns in a single MySQL query?
- MySQL update multiple records in a single query?
- Update multiple rows in a single column in MySQL?
- MySQL query to select multiple rows effectively?
- MySQL query to count rows in multiple tables
- How to count rows from two tables in a single MySQL query?
- How can I get the output of multiple MySQL tables from a single query?
Advertisements