- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 obtain multiple rows in a single MySQL query?
To obtain multiple rows in a single MySQL query, use LIKE operator. Let us first create a table −
mysql> create table DemoTable1385 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.90 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1385(Name) values('Chris Brown'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1385(Name) values('Adam Smith'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1385(Name) values('Carol Taylor'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1385(Name) values('John Doe'); Query OK, 1 row affected (0.48 sec) mysql> insert into DemoTable1385(Name) values('John Smith'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1385;
This will produce the following output −
+----+--------------+ | Id | Name | +----+--------------+ | 1 | Chris Brown | | 2 | Adam Smith | | 3 | Carol Taylor | | 4 | John Doe | | 5 | John Smith | +----+--------------+ 5 rows in set (0.00 sec)
Here is the query to obtain multiple rows in a single MySQL query −
mysql> select * from DemoTable1385 where Name LIKE '%Smith';
This will produce the following output −
+----+------------+ | Id | Name | +----+------------+ | 2 | Adam Smith | | 5 | John Smith | +----+------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to get 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?
- How to count rows from two tables in a single MySQL query?
- Update multiple rows in a single column in MySQL?
- Implement multiple COUNT() in a single MySQL query
- Change multiple columns in a single MySQL query?
- MySQL update multiple records in a single query?
- MySQL query to count rows in multiple tables
- MySQL query to select multiple rows effectively?
- How to update multiple rows using single WHERE clause in MySQL?
- Implement multiple LIKE operators in a single MySQL query

Advertisements