delete where not in another table - Mailing list pgsql-sql

From Campbell, Lance
Subject delete where not in another table
Date
Msg-id B75CD08C73BD3543B97E4EF3964B7D701F353B73@CITESMBX1.ad.uillinois.edu
Whole thread Raw
Responses Re: delete where not in another table
List pgsql-sql
<div class="WordSection1"><p class="MsoNormal">If I have two tables, T1 and T2, such that both have the same primary
keyof “user_id”.<p class="MsoNormal">What is the SQL I would use to delete all rows from T1 that are not in T2?<p
class="MsoNormal"> <pclass="MsoNormal">This is one way to write the SQL but it is really inefficient:<p
class="MsoNormal"> <pclass="MsoNormal">DELETE FROM T1 WHERE T1.user_id NOT IN (SELECT user_id FROM T2 WHERE
T2.user_id=T1.user_id);<p class="MsoNormal"> <p class="MsoNormal">I was thinking there should be a way to write this
witha join.<p class="MsoNormal"> <p class="MsoNormal"> <p class="MsoNormal"> <p class="MsoNormal">Thanks,<p
class="MsoNormal"> <pclass="MsoNormal">Lance Campbell<p class="MsoNormal">Software Architect<p class="MsoNormal">Web
Servicesat Public Affairs<p class="MsoNormal">217-333-0382<p class="MsoNormal"
style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><ahref="http://illinois.edu/"><span
style="font-size:9.0pt;font-family:"Arial","sans-serif";color:blue;text-decoration:none"><imgalt="University of
Illinoisat Urbana-Champaign logo" border="0" height="33" id="Picture_x0020_1" src="cid:image003.png@01CE7CB0.2050FD30"
width="195"/></span></a><span style="font-size:9.0pt;font-family:"Arial","sans-serif";color:blue"></span><p
class="MsoNormal"> <pclass="MsoNormal"> </div> 

pgsql-sql by date:

Previous
From: David Johnston
Date:
Subject: Re: Update a composite nested type variable
Next
From: Igor Neyman
Date:
Subject: Re: delete where not in another table