Unix Technical Forum

Query Two Databases

This is a discussion on Query Two Databases within the MySQL General forum forums, part of the MySQL category; --> Not sure if this is possible or not. But I've two identical tables in two different databases. Is it ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 05:40 AM
Neil Tompkins
 
Posts: n/a
Default Query Two Databases

Not sure if this is possible or not. But I've two identical tables in two
different databases. Is it possible to retrieve data from the different
tables in one query ?

Thanks
Neil

__________________________________________________ _______________
MSN Hotmail is evolving – check out the new Windows Live Mail
http://ideas.live.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 05:40 AM
Martijn Tonies
 
Posts: n/a
Default Re: Query Two Databases




> Not sure if this is possible or not. But I've two identical tables in two
> different databases. Is it possible to retrieve data from the different
> tables in one query ?


Yes, by using this notation:

select *
from mydatabase.mytable

Martijn Tonies
Database Workbench - development tool for MySQL, and more!
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 05:40 AM
=?ISO-8859-15?Q?Nils_J=FCnemann?=
 
Posts: n/a
Default Re: Query Two Databases

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Neil Tompkins schrieb:
> Not sure if this is possible or not. But I've two identical tables in
> two different databases. Is it possible to retrieve data from the
> different tables in one query ?


(SELECT * FROM db1.table) UNION (SELECT * FROM db2.table)

If db2 on a other mysql server, it is possible to use the
federated storage engine of MySQL.

- --
Nils Jünemann
Database and System Administration

studiVZ | Saarbrueckerstr. 38 | 10405 Berlin | phone +49-(0)30-405042715
www.studiVZ.net | fax +49-(0)30-28093887 | cell +49-(0)175-9331740
www.estudiLN.es | www.studentIX.pl | www.studiQG.fr | www.studiLN.it
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFuI4cYT5ehyp2X5ERAh/AAKCEDPXhlegrCu08jG0K3Eh/ZxIfgwCeIbZz
hJRxd5b07AxIlFP8/RBKQx0=
=G/4h
-----END PGP SIGNATURE-----
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 05:40 AM
Neil Tompkins
 
Posts: n/a
Default Re: Query Two Databases

The databases are on the same server, however the login details for each
database are different.




>From: "Martijn Tonies" <m.tonies@upscene.com>
>To: <mysql@lists.mysql.com>
>Subject: Re: Query Two Databases
>Date: Thu, 25 Jan 2007 11:56:37 +0100
>
>
>
>
> > Not sure if this is possible or not. But I've two identical tables in

>two
> > different databases. Is it possible to retrieve data from the different
> > tables in one query ?

>
>Yes, by using this notation:
>
>select *
>from mydatabase.mytable
>
>Martijn Tonies
>Database Workbench - development tool for MySQL, and more!
>Upscene Productions
>http://www.upscene.com
>My thoughts:
>http://blog.upscene.com/martijn/
>Database development questions? Check the forum!
>http://www.databasedevelopmentforum.com
>
>
>--
>MySQL General Mailing List
>For list archives: http://lists.mysql.com/mysql
>To unsubscribe:
>http://lists.mysql.com/mysql?unsub=n...ns@hotmail.com
>


__________________________________________________ _______________
Find Love This New Year With match.com! http://msnuk.match.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 05:40 AM
Duncan Hill
 
Posts: n/a
Default Re: Query Two Databases

On Thursday 25 January 2007 11:08, Neil Tompkins wrote:
> The databases are on the same server, however the login details for each
> database are different.
>


A query executes with the credentials of the authentication used to set up the
connection. If you want to query two tables simultaneously across two
databases, the user used to run the query will need SELECT access to both
database.tables.
--
Scanned by iCritical.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 05:40 AM
Martijn Tonies
 
Posts: n/a
Default Re: Query Two Databases



> The databases are on the same server, however the login details for each
> database are different.


Hmm, I guess that the currently connected user needs to have access
to both databases, how else would it get the data?

Martijn Tonies
Database Workbench - development tool for MySQL, and more!
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 05:47 AM
Neil Tompkins
 
Posts: n/a
Default Re: Query Two Databases

At the moment we are using mysql 3.23.58. It would appear I can't use UNION
in this version ?

Do I have any other options, without upgrading the database server version ?

Regards,
Neil




>From: Nils Jünemann <njuenemann@studivz.net>
>To: mysql@lists.mysql.com
>Subject: Re: Query Two Databases
>Date: Thu, 25 Jan 2007 12:01:48 +0100
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Neil Tompkins schrieb:
> > Not sure if this is possible or not. But I've two identical tables in
> > two different databases. Is it possible to retrieve data from the
> > different tables in one query ?

>
>(SELECT * FROM db1.table) UNION (SELECT * FROM db2.table)
>
>If db2 on a other mysql server, it is possible to use the
>federated storage engine of MySQL.
>
>- --
>Nils Jünemann
>Database and System Administration
>
>studiVZ | Saarbrueckerstr. 38 | 10405 Berlin | phone +49-(0)30-405042715
>www.studiVZ.net | fax +49-(0)30-28093887 | cell +49-(0)175-9331740
>www.estudiLN.es | www.studentIX.pl | www.studiQG.fr | www.studiLN.it
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.4.6 (MingW32)
>Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
>iD8DBQFFuI4cYT5ehyp2X5ERAh/AAKCEDPXhlegrCu08jG0K3Eh/ZxIfgwCeIbZz
>hJRxd5b07AxIlFP8/RBKQx0=
>=G/4h
>-----END PGP SIGNATURE-----
>
>--
>MySQL General Mailing List
>For list archives: http://lists.mysql.com/mysql
>To unsubscribe:
>http://lists.mysql.com/mysql?unsub=n...ns@hotmail.com
>


__________________________________________________ _______________
MSN Hotmail is evolving – check out the new Windows Live Mail
http://ideas.live.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:17 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com