Newbie question about multiple databases

if i have this query:
SELECT * FROM books2006, books2007;


(books 2006 and 2007 have exactly the same fields.)

how can i tell if the data was retrieved from books2006 or books2007
(whitout changing anything in the databases) ?

in other words is there any way that along the information that i
retrieve from the fields (ex. author, date_published, isbn) that i
also get the name of the database from which i retrieved the
information?

thank you very much,

GD
GD [ Fr, 13 Juli 2007 19:17 ] [ ID #1767916 ]

Re: Newbie question about multiple databases

I think you mean different tables, not different databases. It's
distinctly more difficult to select information from separate
databases in the same query (if not impossible). In any case, I think
the best case to deal with your problem is the PHP function
mysql_fetch_field http://www.php.net/mysql_fetch_field. It returns an
object, so you can call:
$table = mysql_fetch_field($result, $colNum)->table; to get the table
name of the colum in position $colNum.

Hope that helps!
dimo414 [ Fr, 13 Juli 2007 21:04 ] [ ID #1767917 ]

Re: Newbie question about multiple databases

Michael wrote:
> I think you mean different tables, not different databases. It's
> distinctly more difficult to select information from separate
> databases in the same query (if not impossible). In any case, I think
> the best case to deal with your problem is the PHP function
> mysql_fetch_field http://www.php.net/mysql_fetch_field. It returns an
> object, so you can call:
> $table = mysql_fetch_field($result, $colNum)->table; to get the table
> name of the colum in position $colNum.
>
> Hope that helps!

Oh it is just SO difficult to get information from separate databases in the
same query:

SELECT * FROM database1.books2006, database2.books2007;

Wasn't that just so difficult - nearly impossible!
http://dev.mysql.com/doc/refman/5.0/en/identifier-qualifiers .html
Paul Lautman [ Sa, 14 Juli 2007 11:20 ] [ ID #1768554 ]

Re: Newbie question about multiple databases

On Fri, 13 Jul 2007 19:04:33 -0000, Michael <dimo414 [at] gmail.com> wrote:

>I think you mean different tables, not different databases. It's
>distinctly more difficult to select information from separate
>databases in the same query (if not impossible). In any case, I think
>the best case to deal with your problem is the PHP function
>mysql_fetch_field http://www.php.net/mysql_fetch_field. It returns an
>object, so you can call:
>$table = mysql_fetch_field($result, $colNum)->table; to get the table
>name of the colum in position $colNum.
>
>Hope that helps!

thank you very much for your response.
You are right i meant different tables, not databases!! sorry about
that.

GD
GD [ Sa, 14 Juli 2007 15:33 ] [ ID #1768556 ]
PHP » alt.php.sql » Newbie question about multiple databases

Vorheriges Thema: can't get to mysql server 4.1 directory on win98se
Nächstes Thema: php 5 upgrade