SELECT tablea.id, COUNT(*) FROM tablea, tableb WHERE tablea.foo = tableb.bar GROUP BY tablea.id