SELECT * FROM repice r WHERE EXISTS ( SELECT NULL FROM ingredients i WHERE i.recipe_id = r.id AND i.ingredient_id IN (1, 2, 3, 4) LIMIT 1 OFFSET 3 )
The OFFSET parameter must be n - 1 , where n is the number of ingredients in the list.
This suggests that the combination (recipe_id, ingredient_id) unique.
source share