FOR i IN 1..100000 LOOP
UPDATE checklist_headers SET area_name = (SELECT name FROM areas WHERE id = (SELECT area_id FROM checklist_headers WHERE id = i)) WHERE id = i;
Not really. The having clause implies an aggregation, which means you don’t have the original rows any more.
I think you want the following:
DELETE from UserPredictions
where UserId in (select UserId from UserPredictions group by UserId having count(*) < 500)