The following code select something from a table on the condition that the ID of the row in the table did not appear in another table.

SELECT table_a.id FROM table_a LEFT JOIN table_b ON table_a.id = table_b.aid WHERE table_b.aid IS NULL;
Source: http://www.tosbourn.com/2010/09/development/mysql-snippet-selecting-from-table-a-items-that-arent-in-table-b/
 

Leave a Comment