- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 can I get the output of multiple MySQL tables from a single query?
As we know that a query can have multiple MySQL statements followed by a semicolon. Suppose if we want to get the result from multiple tables then consider the following example to get the result set from ‘Student_info’ and ‘Student_detail’ by writing a single query −
mysql> Select Name, Address from Student_info; Select Studentid, Address from Student_detail; +---------+------------+ | Name | Address | +---------+------------+ | YashPal | Amritsar | | Gaurav | Chandigarh | | Raman | Shimla | | Ram | Jhansi | | Shyam | Chandigarh | | Mohan | Delhi | | Saurabh | NULL | +---------+------------+ 7 rows in set (0.00 sec) +-----------+------------+ | Studentid | Address | +-----------+------------+ | 100 | Delhi | | 101 | Shimla | | 103 | Jaipur | | 104 | Chandigarh | | 105 | Chandigarh | +-----------+------------+ 5 rows in set (0.00 sec)
In the example above, two statements have been entered on a single line separated by a semicolon and we got the output in sequence.
Advertisements