Skip to content
Advertisement

MySQL Select distinct rows with same id with different value in a column and excluded a specific value in another column

I have a MySQL database table like following:

I want to select id’s who have multiple users. In this condition users 1 and 2 are valid. But the problem is, along with above condition I also wanted to select those who do not have a task_id = 10. So final output should be id = 1.

I achieved first condition fulfilled by the help of this post.

But could not achieved result excluding task_id = 10 because trying with following query, it is still showing both users 1 and 2.

Advertisement

Answer

Just use aggregation and having;

If you wanted the original rows, I would express this using exists:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement