mldev
mldev

Reputation: 21

Query to find ID with multiple entries based on a 2nd column with multiple values?

I have the following problem i want to select product_id from feature_values table where variant_id equals multiple values

I have this

SELECT product_id FROM feature_values WHERE variant_id = '162' AND variant_id = '11819'

The above returns no results

The following two queries return the product_id

SELECT product_id FROM feature_values WHERE variant_id = '162'

and this

SELECT product_id FROM feature_values WHERE variant_id = '11819'

Table example data

Feature ID, Product ID, Variant ID, Value
        92,        565,      11815
        69,        565,        162
        92,        566,      11819
        69,        566,        162

Upvotes: 0

Views: 64

Answers (2)

user2009750
user2009750

Reputation: 3187

Try these, AND is not what you are looking for, Think logically variant id can be either one or the other not both at the same time.

SELECT product_id FROM feature_values WHERE variant_id IN ('162', '11819')

OR

SELECT product_id FROM feature_values WHERE variant_id = '162' OR variant_id = '11819'

Upvotes: 1

Sorin
Sorin

Reputation: 5395

SELECT product_id FROM feature_values WHERE variant_id = '162' OR variant_id = '11819'

or

SELECT product_id FROM feature_values WHERE variant_id in ('162','11819') 

Upvotes: 1

Related Questions