rmck wrote:
I have two tables:

DB 1:
Table A:
Userid: Dept:


DB 2:
Table B:
Userid:
Dept:
Location:

How would I query from DB 1 Table A for the Dept if I want to use that value for DB 2's Dept?
Both DBs and tables have the same Userid.


Does not work:
Use 2;
Select A.Dept from A where B.Userid = 'sam';

I have to do the query using db 2.

I hope this is not to dump of a question. Thanks.

Thanks,
Rob

I don't entirely understand what you really want, but, in general, you put the db name in front of the table name when you want to reference a table in a different db.


Given your sample query, I can't see why you wouldn't simply

  USE 1;
  SELECT Dept FROM A WHERE Userid = 'Sam';

but if you are determined to stay with db 2, you can do it like this:

  USE 2;
  SELECT Dept FROM 1.A WHERE Userid = 'Sam';

Perhaps what you really want is to join the two tables. Then you'd do something like

  USE 2;
  SELECT B.Userid, 1.A.Dept
  FROM 1.A
  JOIN B ON 1.A.Userid = b.Userid;

or perhaps

  SELECT 2.B.Userid, 1.A.Dept
  FROM 1.A
  JOIN 2.B ON 1.A.Userid = 2.B.Userid;

which should work regardless of the current db.

Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to