I’ve been struggling with this for a while, and haven’t been able to find any examples to point me in the right direction.
I have 2 MySQL tables that are virtually identical in structure. I’m trying to perform a query that returns results from Table 1 where the same data isn’t present in table 2. For example, imagine both tables have 3 fields – fieldA, fieldB and fieldC. I need to exclude results where the data is identical in all 3 fields.
Is it even possible?
This is a perfect use of
EXCEPT(the key word/phase is “set difference”). However, MySQL lacks it. But no fear, a work-around is here:Intersection and Set-Difference in MySQL (A workaround for EXCEPT)
Please not that approaches using
NOT EXISTSin MySQL (as per above link) are actually less than ideal although they are semantically correct. For an explanation of the performance differences with the above (and alternative) approaches as handled my MySQL, complete with examples, see NOT IN vs. NOT EXISTS vs. LEFT JOIN / IS NULL: MySQL:Happy coding.