Home > Database > Mysql Tutorial > Can I perform SQL SELECT statements across multiple databases on the same server?

Can I perform SQL SELECT statements across multiple databases on the same server?

Susan Sarandon
Release: 2024-11-12 08:58:02
Original
950 people have browsed it

Can I perform SQL SELECT statements across multiple databases on the same server?

Selecting Columns Across Multiple Databases

Is it possible to perform SQL SELECT (or INSERT) statements across multiple databases residing on the same server? If so, how?

Solution:

Yes, it is possible to access columns from different databases in a single query. To do so, specify the database name followed by the period (.) character and then the table name.

Database Name Syntax:

databasename.tablename
Copy after login

Example Query:

SELECT
    mydatabase1.tblUsers.UserID,
    mydatabse2.tblUsers.UserID
FROM
   mydatabase1.tblUsers
       INNER JOIN mydatabase2.tblUsers
           ON mydatabase1.tblUsers.UserID = mydatabase2.tblUsers.UserID
Copy after login

In this example, the query retrieves the UserID columns from two tables, tblUsers, located in the mydatabase1 and mydatabse2 databases.

The above is the detailed content of Can I perform SQL SELECT statements across multiple databases on the same server?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template