Hello!
I have 2 databases located on the same server. I need to select data from both databases in one query because I want to be able to sort by fields in the first database or the second database. Here's the way it looks:
db1 has a user table with user_id, name
db2 has a customer table with customer_id, email_address
I need a select statement that will select user_id and name from db1 and email_address from db2 where user_id = customer_id and I need to be able to sort by either user_id, name or email_address (depending upon what's chosen in my PHP form).
Any help would be GREATLY appreciated!!!
Select from 2 Databases
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
SELECT
database1.table1.field1,
database1.table2.field1,
database2.table1.field1
FROM
database1.table1
INNER JOIN
database1.table2
ON
database1.table1.field1 = database1.table2.field3
INNER JOIN
database2.table1
ON
database1.table2.field2 = database2.table1.field2