Solved

How to delete records that not exist in TABLEB

Posted on 2013-01-13
3
348 Views
Last Modified: 2013-01-14
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
Comment
Question by:team2005
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
Comment Utility
DELETE FROM TABLEA
FROM TABLEA LEFT JOIN
    TABLEB ON TABLEA.ITEMID = TABLEB.ITEMID
WHERE TABLEB.ITEMID IS NULL
0
 
LVL 41

Assisted Solution

by:pcelba
pcelba earned 250 total points
Comment Utility
I would recommend slower (obviously) but better readable syntax:

DELETE FROM TABLEA
  WHERE ITEMID NOT IN (SELECT ITEMID FROM TABLEB)
0
 
LVL 2

Author Closing Comment

by:team2005
Comment Utility
Thanks
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now