counting matches between multiple tables

G

Guest

Hi

I need to create a query which counts the number of matches between data in
a certain field within a 'master table' and corresponding fields in several
other tables, and display the results in a summary table. I've tried using a
union query to combine multiple select joins but I can't figure out how to
retrieve and display the different table names alongside the count for each
table.

I need to end up with something like this:

Tablename rowsmatching
table1 100
table2 250

Any ideas?
Thanks
Stefan
 
M

MGFoster

stef22 said:
Hi

I need to create a query which counts the number of matches between data in
a certain field within a 'master table' and corresponding fields in several
other tables, and display the results in a summary table. I've tried using a
union query to combine multiple select joins but I can't figure out how to
retrieve and display the different table names alongside the count for each
table.

I need to end up with something like this:

Tablename rowsmatching
table1 100
table2 250

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

SELECT 'table1' As TableName, Count(*) As RowsMatching
FROM table1
WHERE colA IN (SELECT ColA FROM master_table WHERE <criteria>)

UNION

SELECT 'table2', Count(*)
FROM table2
WHERE colA IN (SELECT ColA FROM master_table WHERE <criteria>)

UNION ... etc. ...
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmf8sIechKqOuFEgEQLrGwCfUsNYfiFu1bIKCngEiSb5gGsQxHoAoNHJ
OUfPI9vvPtysexjjuGHd0lBQ
=dV+O
-----END PGP SIGNATURE-----
 
G

Guest

thanks very much!

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

SELECT 'table1' As TableName, Count(*) As RowsMatching
FROM table1
WHERE colA IN (SELECT ColA FROM master_table WHERE <criteria>)

UNION

SELECT 'table2', Count(*)
FROM table2
WHERE colA IN (SELECT ColA FROM master_table WHERE <criteria>)

UNION ... etc. ...
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQmf8sIechKqOuFEgEQLrGwCfUsNYfiFu1bIKCngEiSb5gGsQxHoAoNHJ
OUfPI9vvPtysexjjuGHd0lBQ
=dV+O
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top