SELECT c.category_name, i.image_id FROM categories c
CROSS JOIN LATERAL (
  SELECT image_id
  FROM image_hashes v
  WHERE v.category_id = c.category_id
  LIMIT 5
) i;
