I’ve a MySql table which contains rows like,
pid | country |
---|---|
436 | 1 |
436 | 5 |
436 | 7 |
439 | 7 |
440 | 3 |
446 | 7 |
446 | 1 |
For Example, I am trying to retrieve products which has only country 7 and should not present in other combination. How can I achieve this?
I tried like below:
SELECT * from table_name WHERE country = 7;
but outcome/result contains pid 436,439 and 336. It should only give 439.
2
Answers
You can use not exists for this:
We can use aggregation here: