Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to delete records that not exist in TABLEB

Posted on 2013-01-13
3
Medium Priority
?
354 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 43

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

597 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