MySQL full outer join workaround
Is it possible to do a joint query for 2 tables in MySQL to compare the fields, whether the data used is the same in both the tables or not?

    Requires Free Membership to View

    When you register, my team of editors will also send you resources covering Linux administration and management; integration and interoperability between Linux, Windows and Unix; securing Linux and mixed-platform environments; and migrating to Linux.

    Margie Semilof, Editorial Director

    By submitting your registration information to SearchEnterpriseLinux.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchEnterpriseLinux.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

Yes. The easiest way assumes that you have some ID field that should match in both tables. You can then join the tables on that ID and compare the other fields in the table for differences:
SELECT *
FROM
  table1
  JOIN table2 ON table1.id = table2.id 
WHERE
  (table1.field1, table1.field2, table1.field3) != (table2.field1, table2.field2, table3.field3)

If the tables have no ID field in common, you might need a full outer join to find the differences between the tables. MySQL doesn't offer syntax for a full outer join, but you can implement one using the union of a left and a right join. Since no indexes are likely to be used, expect for these results to take a long time on tables of any significant size.

SELECT *
FROM
  table1
  LEFT JOIN table2 ON (table1.field1, table1.field2, table1.field3) = (table2.field1, table2.field2, table3.field3)
WHERE
  table2.field1 IS NULL
UNION
SELECT *
FROM
  table1
  RIGHT JOIN table2 ON (table1.field1, table1.field2, table1.field3) = (table2.field1, table2.field2, table3.field3)
WHERE
  table1.field1 IS NULL

This was first published in March 2007