A have the following data
x
id user_id visited_country
1 12 Spain
2 12 France
3 14 England
4 14 France
5 16 Canada
6 14 Spain
I want to select all users who have visited both Spain and France. How can I do that in MySQL?
Advertisement
Answer
Something like the following should suffice:
select user_Id
from t
where visited_country in ('Spain','France')
group by User_Id
having Count(distinct visited_country) = 2;