Reputation: 5596
I want all product_id's having website_id = 0(Zero) and not having other value. Following is my table data,
+------------+------------+
| product_id | website_id |
+------------+------------+
| 19112 | 0 |
| 19112 | 1 |
| 19112 | 2 |
| 19113 | 1 |
| 19110 | 0 |
| 19110 | 2 |
| 19114 | 0 |
| 19115 | 0 |
| 19115 | 1 |
| 19116 | 0 |
+------------+------------+
I want following rows from above table data;
+------------+------------+
| product_id | website_id |
+------------+------------+
| 19114 | 0 |
| 19116 | 0 |
+------------+------------+
Can any one help me with query. Thank you!.
Upvotes: 1
Views: 54
Reputation: 63
select product_id,website_id
from table_name
group by product_id
having sum(website_id) < 1
More Simplified version.
Upvotes: 0
Reputation: 64486
To get the desired result you can use following query
select product_id,website_id
from t
group by product_id
having count(*)=sum(website_id = 0)
Upvotes: 7