0

i don't find a solution for this and need a good tip.

This is the table:

Name,Status
A, 3
A, 4
B, 3

I like do get all results where Status is like 3 but never got Status=4.

In this example: only B should be shown. How should my query look like? Thank you!!

3
  • Select * from table where status =3; try this Commented Jul 2, 2018 at 10:20
  • 1
    This would also show "A"- But A also has an entry status =4. And should not be shown. I like to see only the ones, who have not an entry =3 AND =4. Only the ones which have 3 only. Commented Jul 2, 2018 at 10:22
  • so yes it will give results where status is only 3. if you want to get want to you need to chnage your query select * from table where name ='A'; it will give status 3 and 4 as well Commented Jul 2, 2018 at 10:24

2 Answers 2

1

Try this :

Select t1.* 
from tableName t1
where t1.status =3 AND NOT EXISTS (SELECT 1 
                                   FROM TableName t2
                                   WHERE t1.Name = t2.Name AND t2.status = 4)
Sign up to request clarification or add additional context in comments.

Comments

0
select t.Name
from my_table t
where t.Status in (3,4)
group by t.Status
having group_concat(t.Status) = '3'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.