SELECT (line / 50000) + 1 AS sitemap_file
,line
,item_type_id
,item_id
FROM (
SELECT row_number() OVER() AS line
,item_type_id
,item_id
FROM flags
WHERE site_id = 234
AND item_type_id != 5
AND parent_item_type_id NOT IN (3, 5)
ORDER BY last_modified ASC
) AS f
ORDER BY line ASC
LIMIT 50
I need a scratchpad... this will do: