Newbie question about multiple databases

Newbie question about multiple databases

am 13.07.2007 19:17:14 von GD

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

Re: Newbie question about multiple databases

am 13.07.2007 21:04:33 von dimo414

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!

Re: Newbie question about multiple databases

am 14.07.2007 11:20:47 von Paul Lautman

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

Re: Newbie question about multiple databases

am 14.07.2007 15:33:23 von GD

On Fri, 13 Jul 2007 19:04:33 -0000, 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!

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

GD