Q:

Select empty clans from database

I have two tables: accounts and clans
There is a hasMany relationship between these two. 
One clan can have multiple accounts: accounts.clanId points to clans.clanId
How can I select all empty clans that don't have any accounts? 

A:

One way is to do a LEFT JOIN between the two tables and retain those clan records which did not map to any accounts:
SELECT c.*
FROM clans c
LEFT JOIN accounts a
    ON c.clanId = a.clanId
WHERE a.clanId IS NULL

