MySQL snippet - Selecting from table a items that aren't in table b.

Today I needed to select something from a table on the condition that the ID of the row in the table did not appear in another table.

Initially I thought this was going to be slightly difficult to do, or at least a bit convoluted but it turned out to be really simple.

SELECT FROM table_a LEFT JOIN table_b ON = table_b.aid WHERE table_b.aid IS NULL;

Since you are using a LEFT JOIN table_b.aid can return NULL values, and these are the ones you are looking for.

Recent posts View all

Simple CS


Let's learn about Compilers, what they are and how they work.


Adding an integration to a Slack room

How to add an integration to a Slack room. Part of our Slack mini series.