Skip to content
Advertisement

select only those who have no contact

I updated my question.

I have table like this:

id name contact
1 A 65489
1 A
1 A 45564
2 B

so, i want table like this:

id name contact
2 B

Advertisement

Answer

Using exists logic we can try:

SELECT *
FROM yourTable t1
WHERE NOT EXISTS (SELECT 1 FROM yourTable t2
                  WHERE t2.id = t1.id AND t2.contact IS NOT NULL);

In plain English, the above query says to return any records for which we cannot find another record belonging to the same id group having a non NULL contact value.

Here is a demo of the query.

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