Domanda

Is there a way to use IN and AND together? The problem is that I want to match my query to multiple values using one column.

SELECT * FROM product INNER JOIN values USING(product_id) WHERE value = "large" AND value = "short"

The problem is I can't use the IN clause, because it defines as OR between the values.

È stato utile?

Soluzione

Try:

select product_id
from values
where value in ('large','short')
group by product_id
having count(distinct value) = 2

Altri suggerimenti

No, that's not possible, because it doesn't make any sense at all.

A field can not be equal to two different values at the same time. The expression x = y and x = z will always be false when y and z have different values.

(The exception would be some text values that could be considered equal in some cultures, like the and thé, but the comparison still doesn't make any sense in that case.)

No. both IN and AND operators are different if you are using your queries in the below manner.

This SQL doesnt make any sense.I am just trying to compare the wrong one with the right one. SELECT * FROM product INNER JOIN values USING(product_id) WHERE value = "large" AND value = "short"

SELECT * FROM product INNER JOIN values USING(product_id) WHERE value IN ("large","short");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top