Re: Query 2 MySQL databases in 1 statement



noor.rahman@xxxxxxxxx wrote:
I was wondering how it may be possible to query 2 MySQL databases using
one query statement from PHP.

For instance: SELECT database1.tableA.field1 UNION
database2.tableB.field2.

My concern is, when connecting to MySQL (or sending a query), I only
specify 1 database connection resource ID. How does that play out when
connecting to 2 databases?

Thanks.


As I understand it, the database you specify when connecting to mysql
is your default database. For example, if you connect using "db1",
then to query that database, you can just use "SELECT * FROM table1"
which, because of your default database, is equivalent to "SELECT *
FROM db1.table1". You are still able to access other databases by
fully-qualifying the names, so even if "db1" is your default database,
you can still do something like "SELECT * FROM db2.table2".

.



Relevant Pages

  • Re: Using a Select Query to build a MDB table from a Fox table
    ... MS Access has a 'make-table' query with IN clause you can specify ... As you said the IN <database> clause is specific to Access SQL. ...
    (microsoft.public.fox.helpwanted)
  • Re: default select order
    ... database version is 10.2.0.1.0. ... Now I'm wondering why 10g2 works like this (every time I query)? ... Ei kaytossa (refers to E) ... If you do not specify an order by clause then the order the results come ...
    (comp.databases.oracle.server)
  • Re: Sort database alphabetically
    ... What I am saying is that you cannot sort the database, ... So all you need to do is add "ORDER BY Name" to your existing query. ... In the Query Designer screen use the Sort Order column to specify ...
    (microsoft.public.sqlserver.server)
  • Re: How to specify the name of the database to export to in a make table query
    ... parameter in the query rather than as something explicitly specified within ... I have tried IN [Enter filename and path]. ... >> I need to know whether it is possible to specify the name of a database ...
    (microsoft.public.access.queries)
  • RE: HOWTO programmtically code use in T-SQL
    ... Analyzer, you are connecting to a server, so switching databases at will is ... a specific database where USE has no meaning. ... > How can one programmticaly code the 'use' statement in T-SQL so that from> both Query Analyzer and a typical ADO/ODBC query one can change whatever DB a> TX is "pointed" to to "point" to the DB they really want to work work. ...
    (microsoft.public.sqlserver.programming)