Richard,
On Fri, Mar 16, 2001 at 06:05:52PM -0600, Richard Reina wrote:
> I am try to do a join with tables that are in two different databases.
>
> I thing I've got the actual SQL syntax down:
>
> my $q = "SELECT i.inv_no, i.inv_date,
> c.cust_name
> FROM receivables.invoice i, sales.customer c,
> WHERE i.paid_date IS NULL";
>
> but I am confused on how to prepare and execute it, since my database
> handle ($dbh) specifies only 1 database.
>
The database handle defines the default database. So if your database handle
is on the receivables database, your query can be:
my $q = "SELECT i.inv_no, i.inv_date,
c.cust_name
FROM invoice i, sales.customer c,
WHERE i.paid_date IS NULL";
I.e. invoice i.s.o. receivables.invoice. Your query above will work regardless
of the database that your handle is for.
The only limitation is that the databases are managed by the same MySQL server.
Just try it.
One more thing about your query. You're doing a full join of the two tables.
You probably want something like "AND i.customer_id = c.id" in the WHERE
clause.
Regards,
Fred.
--
Fred van Engen XO Communications B.V.
email: [EMAIL PROTECTED] Televisieweg 2
tel: +31 36 5462400 1322 AC Almere
fax: +31 36 5462424 The Netherlands
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php