How do I select differing rows in two MySQL tables with the same structure?

Posted by chiborg on Stack Overflow See other posts from Stack Overflow or by chiborg
Published on 2010-03-16T17:25:57Z Indexed on 2010/03/16 18:01 UTC
Read the original article Hit count: 269

Filed under:
|
|
|

I have two tables, A and B, that have the same structure (about 30+ fields). Is there a short, elegant way to join these tables and only select rows where one or more columns differ? I could certainly write some script that creates the query with all the column names but maybe there is an SQL-only solution.

To put it another way: Is there a short substitute to this:

SELECT *
FROM   table_a a
  JOIN table_b b ON a.pkey=b.pkey
WHERE  a.col1 != b.col2
    OR a.col2 != b.col2
    OR a.col3 != b.col3 # .. repeat for 30 columns

© Stack Overflow or respective owner

Related posts about mysql

Related posts about column