Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

How to delete records that not exist in TABLEB

Hi!

Have two tables -> TABLEA and TABLEB

I want to check if condision TABLEA.ITEMID exist in TABLEB.ITEMID
If TABLEA.ITEMID dosent exist in TABLEB.ITEMID
it must delete the record from TABLEA

How can i do this ?
0
team2005
Asked:
team2005
2 Solutions
 
Patrick MatthewsCommented:
DELETE FROM TABLEA
FROM TABLEA LEFT JOIN
    TABLEB ON TABLEA.ITEMID = TABLEB.ITEMID
WHERE TABLEB.ITEMID IS NULL
0
 
pcelbaCommented:
I would recommend slower (obviously) but better readable syntax:

DELETE FROM TABLEA
  WHERE ITEMID NOT IN (SELECT ITEMID FROM TABLEB)
0
 
team2005Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now