Yogesh k
Yogesh k

Reputation: 352

Search for exact match of parameters mysql

I am searching in below table for size 2. But after return of results I am getting two rows having product id's 1,2. As because product id 1,2 contains size 2. But product with id 2 contains other sizes also. That is 3 and 5. And I am looking only for size 2.

So what exactly I want is final results will contain only one row as product id 1. As because I am only searching for size 2.

So how should I achieve this.

Upvotes: 1

Views: 205

Answers (2)

Bibhudatta Sahoo
Bibhudatta Sahoo

Reputation: 4894

After altos of research i got the solution
Try this query:-

 SELECT * FROM `product` 
 where size in ('2','3','5') and
 product_id not in (select product_id FROM `product` where size not in ('2','3','5'))

In place of ('2','3','5') you have to pass your ids like this only.
According to your data this query will produce out put as

enter image description here

I thing it will help you.

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1269643

You can do this with group by and having:

select product_id
from t
group by product_id
having min(size) = max(size) and min(size) = 2;

Upvotes: 0

Related Questions