Jump to content

problem with querying from 2 databases


jeff5656

Recommended Posts

I trying to join two tables in 2 separate databases, mainbill and demo. 

 

$query2 = "SELECT * FROM mainbill.notes inner join mainbill.notes ON mainbill.notes.id = demo.notes_list.bill_id";

When I run this query I get:

 

Not unique table/alias: notes.

 

Now I do not have a notes table in the demo database so I can't figure out what the problem is.  Both databases are on the same server.

Link to comment
https://forums.phpfreaks.com/topic/242080-problem-with-querying-from-2-databases/
Share on other sites

well to put it plainly, you can't however by indicating the database in your select query, MYSQL allows another database to be called...so that's not the issue here..

 

1. Are you sure that you can execute query's with the given connection information?

 

2. Which database are you using in your mysql_select_db?

 

here's the connect code right before that query:

$dbhost = "localhost";
$dbname = "xxxx_mainbill";
$dbuser = "xxxxx_yyyy";
$dbpass = "xxxxx";

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

Importantly, the dbuser and dbpassword is the same for the other database (demo)

Ok I'm sorry I think I just wasted all of your time.  I was not naming the databases correctrly.  for example the database is called

myusername_demo  NOT

demo

 

I a really sorry but at least I still needed the correct JOIN command which you guys did help me with so all is not lost!

Thanks again...

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.