Search for non-duplicates bettween two tables.

Categories Information Technology, MySQL, PHP, Programming, Web Development

I recently had some issues trying to make sure that two columns from two different tables were the same.  After some random code writing, I came up with the following MySQL code…  Hope it helps others…

[code]
/* return from first table */
$checkTable1=@mysql_query("SELECT table1.column1 FROM table1 LEFT JOIN table2 ON table2.column2 = table1.coumn1 WHERE table2.column2 IS NULL");

/* return from second table */
$checkTable1=@mysql_query("SELECT table2.column2FROM table2 LEFT JOIN table1 ON table1.column1 = table2.column2 WHERE table1.column1 IS NULL");
[/code]

I’m sure there is a better way to accomplish it, but this worked for my needs…  Just a quick search, and then I added some extra code to update the tables if there are any discrepancies.

–Charles…