I have a table orders:
|--------------------|-----------------|------------|
| user_id | article_id | Name |
|--------------------|-----------------|------------|
| 1 | 39 | John |
| 1 | 39 | John |
| 2 | 39 | Mike |
| 2 | 19 | Mike |
| 3 | 39 | Dave |
|--------------------|-----------------|------------|
How can I select only those users who have article_id = 39, regardless of how many times, but if it occurs only once. I would need to select user John and user Dave, but not Mike. Mike has article_id 39, but he also has article_id = 19. The query should return users John and Dave.
I have tried this query:
SELECT * FROM orders AS o where o.article_id = 39
GROUP BY o.user_id HAVING COUNT(o.article_id) > 0
But it return all three users. I don't need user Mike.