?
Solved

How to delete records that not exist in TABLEB

Posted on 2013-01-13
3
Medium Priority
?
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 1000 total points
ID: 38772941
DELETE FROM TABLEA
FROM TABLEA LEFT JOIN
    TABLEB ON TABLEA.ITEMID = TABLEB.ITEMID
WHERE TABLEB.ITEMID IS NULL
0
 
LVL 42

Assisted Solution

by:pcelba
pcelba earned 1000 total points
ID: 38772958
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
ID: 38773532
Thanks
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

752 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