0

How to select a column referenced by a primary key from two databases in the same server?

I would like to select the projects column from clients database with a primary key of project id and I would like to join it with projects database. But I dont know what is the right query.

16th Jun 2017, 12:25 PM
Dani Manalang
Dani Manalang - avatar
7 Respuestas
+ 3
Oh, sorry then :D you can access any database, but you need to know in what schema they belong. So let's say clients database belongs to clients schema. To access table from there, you need to write full name like this: clients.table_name
16th Jun 2017, 1:06 PM
Eligijus Silkartas
Eligijus Silkartas - avatar
+ 3
The second option :)
16th Jun 2017, 2:19 PM
Eligijus Silkartas
Eligijus Silkartas - avatar
+ 2
Thank you!
16th Jun 2017, 2:21 PM
Dani Manalang
Dani Manalang - avatar
+ 1
When joining two different tables, one table has to have a foreign key that references other table's primary key. And when you write select query, you join them on condition, where first table's foreign key is equal to second table's primary key I don't know the correct syntax how to join two tables in MySQL, but you can look it up in their documentation page
16th Jun 2017, 12:54 PM
Eligijus Silkartas
Eligijus Silkartas - avatar
+ 1
So would it be like SELECT clients_db.project_tbl.project_id, projects_db.project_details_tbl.project.id FROM clients_db, projects_db? :D is it right??
16th Jun 2017, 1:11 PM
Dani Manalang
Dani Manalang - avatar
+ 1
Or would it be FROM clients_db.project_tbl, projects_db.project_details_tbl? :D
16th Jun 2017, 1:12 PM
Dani Manalang
Dani Manalang - avatar
0
I actually want to join two different databases 😅
16th Jun 2017, 12:56 PM
Dani Manalang
Dani Manalang - avatar