panthro
panthro

Reputation: 24061

MYSQL IN statement

Im using IN to select stuff...

WHERE categories IN ("red", "blue", "green")

This selects any item in red, blue or green categories, my question is, is there a way to select an item that has to be in all three categories?

Upvotes: 10

Views: 20535

Answers (2)

PatrickH
PatrickH

Reputation: 39

SELECT Item
    FROM YourTable
    WHERE categories ALL ('red', 'blue', 'green')

Upvotes: 0

Joe Stefanelli
Joe Stefanelli

Reputation: 135729

SELECT Item
    FROM YourTable
    WHERE categories IN ('red', 'blue', 'green')
    GROUP BY Item
    HAVING COUNT(DISTINCT categories) = 3

Upvotes: 21

Related Questions