1

I need suggestions on deleting records in relation with another table

Main Table:

c1 c2 c3
2  5  3
1  2  8
1  2  NULL
1  4  7
2  4  8
1  3  NULL
2  5  NULL
5  1  3
1  5  1

I need to delete all rows where c1 and c2 are identical to a row where c3 is NULL.

e.g.: for c3 is NULL if record c1=1 and c2=2 delete that record as well as c1=1, c2=2 and c3=8

The resulting table should be

Main Table:

c1 c2 c3
1  4  7
2  4  8
5  1  3
1  5  1
  • It would be nice if you could provide your sample data in a format like this to make things easier for those trying to help you - there are a couple of articles on how to ask questions here on my profile - you might like to take a look. p.s. welcome to the group! 8-) – Vérace Aug 9 '19 at 20:18
2
DELETE t1
FROM Table t
    JOIN Table t1 ON t1.c1 = t.c1
        AND t1.c2 = t.c2
WHERE t.c3 IS null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.