Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT storyid
- FROM ( SELECT storyid,
- COUNT(DISTINCT categoryid) AS num_categories
- FROM StoryInCategory
- WHERE CategoryID IN (1,2)
- GROUP BY storyid
- ) AS story_category_count
- CROSS JOIN
- (SELECT COUNT(DISTINCT categoryID) AS total_categories
- FROM categories
- WHERE CategoryID IN (1,2)
- ) AS t_categories
- WHERE num_categories = total_categories
Add Comment
Please, Sign In to add comment