To get a counter for each key,
select count(*) as count, ID from Table1 group by ID
So, use this as a subquery in the from clause and join the tables.
select tt1.ID from (select count(*) as count, ID from Table1 group by ID) tt1 inner join (select count(*) as count, ID from Table2 group by ID) tt2 on tt1.ID = tt2.ID where tt1.count < tt2.count
source share