Skip to content

Instantly share code, notes, and snippets.

@mihow
Created January 25, 2024 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihow/a2b094dfe1caf76ea8b723ba46e9c315 to your computer and use it in GitHub Desktop.
Save mihow/a2b094dfe1caf76ea8b723ba46e9c315 to your computer and use it in GitHub Desktop.
5 example matching rows for each category in a joined table (PostgreSQL)
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment