cross checking 2 tables

M

Mario

I have 2 tables with a "OID" field on both, one is the primary and the other
is the related table. What I need to do is to check to see which "OID" is not
on both tables. There is 26,452 records in the primary table and 162,142 in
the related table.

Is there some code for a query that will compare both tables and show me
which "OID's" are not on one of them?
 
M

MGFoster

Mario said:
I have 2 tables with a "OID" field on both, one is the primary and the other
is the related table. What I need to do is to check to see which "OID" is not
on both tables. There is 26,452 records in the primary table and 162,142 in
the related table.

Is there some code for a query that will compare both tables and show me
which "OID's" are not on one of them?

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

Use a LEFT or RIGHT JOIN.

OID that is in primary table and NOT in the related table:

SELECT T1.OID
FROM primary_table AS T1 LEFT JOIN related_table As T2 ON T1.OID =
T2.OID
WHERE T2.OID IS NULL

OID that is in the related table and NOT in the primary table:

SELECT T2.OID
FROM primary_table AS T1 RIGHT JOIN related_table As T2 ON T1.OID =
T2.OID
WHERE T1.OID IS NULL

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

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

iQA/AwUBSasZkYechKqOuFEgEQJC1ACfREUHC3DbmmdhMwCPyJG9HOWI100AnRY3
6ct/zsJsDqieM1k5TpXNZ/J4
=1Sxx
-----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