From: Peter Brawley Date: June 24 2006 10:38pm Subject: Re: selecting data from 2 local DBs with same table structure List-Archive: http://lists.mysql.com/mysql/199279 Message-Id: <449DBED6.90505@earthlink.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=======AVGMAIL-449DBED71765=======" --=======AVGMAIL-449DBED71765======= Content-Type: multipart/alternative; boundary=------------070607040005030105090704 --------------070607040005030105090704 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit >I need the query to select the data from table1 on db1 and then select the >data from table1 on db2 and return a result of where if a field data value >is found in both tables that matches on name for example, it would count the >occurrences. Not entirely clear. Do you mean ... SELECT name, COUNT(field) AS Count1, (SELECT COUNT(field) FROM db2.tbl2 WHERE db2.tbl2.name=db1.tbl1.name) AS Count2 FROM db1.tbl1 GROUP BY name; ? PB ----- Cx Cx wrote: > Hello List! > > Does anybody know how to select and build a result set from two or more > databases with the same table structures that are on the same server. > > I need the query to select the data from table1 on db1 and then select > the > data from table1 on db2 and return a result of where if a field data > value > is found in both tables that matches on name for example, it would > count the > occurrences. > > Thanks in advance > > Craig > > ------------------------------------------------------------------------ > > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.1.394 / Virus Database: 268.9.3/374 - Release Date: 6/23/2006 > --------------070607040005030105090704 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit >I need the query to select the data from table1 on db1 and then select the
>data from table1 on db2 and return a result of where if a field data value
>is found in both tables that matches on name for example, it would count the
>occurrences.

Not entirely clear. Do you mean ...

SELECT
  name,
  COUNT(field) AS Count1,
  (SELECT COUNT(field) FROM db2.tbl2 WHERE db2.tbl2.name=db1.tbl1.name) AS Count2
FROM db1.tbl1
GROUP BY name;

?

PB

-----

Cx Cx wrote:
Hello List!

Does anybody know how to select and build a result set from two or more
databases with the same table structures that are on the same server.

I need the query to select the data from table1 on db1 and then select the
data from table1 on db2 and return a result of where if a field data value
is found in both tables that matches on name for example, it would count the
occurrences.

Thanks in advance

Craig


No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.1.394 / Virus Database: 268.9.3/374 - Release Date: 6/23/2006
--------------070607040005030105090704-- --=======AVGMAIL-449DBED71765======= Content-Type: text/plain; x-avg=cert; charset=us-ascii Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Content-Description: "AVG certification" No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.394 / Virus Database: 268.9.3/374 - Release Date: 6/23/2006 --=======AVGMAIL-449DBED71765=======--