[thelist] MySQL comparing two tables
Ed McCarroll
Ed at ComSimplicity.com
Sun Jan 22 21:30:56 CST 2006
> is there a query I can run that will compare two tables?
Shooting from the hip, here...
To find different values in corresponding fields:
SELECT a.PrimaryKey
FROM TableA a
INNER JOIN TableB b ON a.PrimaryKey = b.PrimaryKey
WHERE a.FieldA <> b.FieldA
OR a.FieldB <> b.FieldB
etc...
To find records in TableA that have no match in TableB:
SELECT a.PrimaryKey
FROM TableA a
LEFT JOIN TableB b ON a.PrimaryKey = b.PrimaryKey
WHERE b.PrimaryKey IS NULL
Then check the other way...
HTH
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ed McCarroll http://www.ComSimplicity.com
(310) 838-4330 PO Box 654, Culver City, CA 90232
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
More information about the thelist
mailing list