Skip to content

Instantly share code, notes, and snippets.

@munro
Created July 6, 2012 23:00
Show Gist options
  • Save munro/3063239 to your computer and use it in GitHub Desktop.
Save munro/3063239 to your computer and use it in GitHub Desktop.
Intersect
-- this seems slow
SELECT listing_id FROM tags WHERE name = 'game_hon'
INTERSECT
SELECT listing_id FROM tags WHERE name = 'west'
INTERSECT
SELECT listing_id FROM tags WHERE name = 'ap'
INTERSECT
(
-- Is there a more efficient way to store this?
SELECT listing_id FROM range_min WHERE name = 'mmr' AND value >= ${min} AND value <= ${max}
UNION
SELECT listing_id FROM range_max WHERE name = 'mmr' AND value >= ${min} AND value <= ${max}
)
SELECT listing_id
FROM tag a
INNER JOIN tag b USING (listing_id)
WHERE a.name = 'beer' AND b.name = 'airconditioning'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment