- 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 execute multiple select queries in MySQL ?
To execute multiple select queries in MySQL, use the concept of DELIMITER. Let us first create a table −
mysql> create table DemoTable1 ( Title text )ENGINE=MyISAM; Query OK, 0 rows affected (0.30 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1 values('The database MySQL is less popular than MongoDB') ; Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1 values('Java language uses MySQL database'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable1 values('Node.js uses the MongoDB') ; Query OK, 1 row affected (0.05 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1;
This will produce the following output −
+-------------------------------------------------+ | Title | +-------------------------------------------------+ | The database MySQL is less popular than MongoDB | | Java language uses MySQL database | | Node.js uses the MongoDB | +-------------------------------------------------+ 3 rows in set (0.00 sec)
Following is the query to create the second table −
mysql> create table DemoTable2 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY ); Query OK, 0 rows affected (0.45 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2 values(),(),(),(),(),(),(),(),(); Query OK, 9 rows affected (0.19 sec) Records: 9 Duplicates: 0 Warnings: 0
Display all records from the table using select statement −
mysql> select *from DemoTable2;
This will produce the following output −
+----+ | Id | +----+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | +----+ 9 rows in set (0.00 sec)
Following is the query to execute multiple select queries −
mysql> DELIMITER // mysql> select *from DemoTable1; select *from DemoTable2; //
This will produce the following output displaying the result of both the select statements −
+-------------------------------------------------+ | Title | +-------------------------------------------------+ | The database MySQL is less popular than MongoDB | | Java language uses MySQL database | | Node.js uses the MongoDB | +-------------------------------------------------+ 3 rows in set (0.00 sec) +----+ | Id | +----+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | +----+ 9 rows in set (0.03 sec)
- Related Articles
- Best way to combine multiple advanced MySQL select queries?
- MySQL Select Multiple VALUES?
- How is it possible for a MySQL trigger to execute multiple statements?
- MySQL query to select multiple rows effectively?
- How to generate multiple insert queries via java?
- How to select row when column must satisfy multiple value in MySQL?
- MySQL select query with multiple WHERE?
- MySQL query to get result from multiple select statements?
- How to apply DISTINCT constraint on select columns in queries in PostgreSQL?
- MySQL Select Statement DISTINCT for Multiple Columns?
- How to select multiple max values which would be duplicate values as well in MYSQL?
- How to select multiple elements with jQuery?
- How to list down all the running queries in MySQL?
- Select multiple columns and display in a single column in MySQL?
- Entering MySQL Queries

Advertisements