Jump to content

join tables from different databases


Gurpinder

Recommended Posts

hi

 

i need to join 2 tables from 2 different databases. I understand that i have to write the full database.dbo.table thing out but I dont know what to put. my database is hosted on godaddy.com

 

this is the hostname provided by godaddy:

dynamicdb.db.8000072.hostedresource.com

 

the other database is:

staticdb.db.8000072.hostedresource.com

 

the query i am running in php is:

	$orders_query=mysql_query("SELECT invoice.Name, order.ID, order.PO_Number, order.Open_Date, order.Closed_Date, order.Status FROM _____????_____ AS order JOIN _____????_____ AS invoice ON order.Invoice_To = invoice.ID WHERE invoice.Sales_Rep='{$_SESSION['Username']}' ORDER BY ID DESC ");

 

I don't know how to write the full location of the database in "_____????_____".

 

CAn someone help?

 

thx

 

 

Link to comment
https://forums.phpfreaks.com/topic/264716-join-tables-from-different-databases/
Share on other sites

not different servers.....2 different databases on the same server

 

Not according to the host names you provided.

 

To join between two databases on the same server, you just do dbname.tablename.  (the .dbo part is a Microsoft SQL Server thing).

For example:

 

SELECT
  *
FROM `userdb`.`users` u
INNER JOIN `orderdb`.`orders` o ON u.userid=o.userid

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.