Archive for the PHP Category

Search for non-duplicates bettween two tables.

Posted in Information Technology, MySQL, PHP, Programming, Web Development with tags , , on 2011.17.02 by w3bguy

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…

/* 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");

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.