You can use conditional aggregation with an outer join select count(*) filter (where at.asset_id is not null) with_unique_id, count(*) filter (where at.asset_id is null) as without_unique_id from assets a left join associated_table at on at.asset_id = a.asset_id;