SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Turning select * from into delete from
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/08/2012 :  20:49:13  Show Profile  Reply with Quote
The following selects the records i want from the table:


Select * FROM dbo.arrest t1
WHERE arrestno NOT IN (SELECT arrestno FROM newgcsowarrants t2 WHERE t2.arrestno=t1.arrestno)


The following moves those rows into a new table:

Select * into dbo.warrantsnotneeded2 FROM dbo.arrest t1
WHERE arrestno NOT IN (SELECT arrestno FROM newgcsowarrants t2 WHERE t2.arrestno=t1.arrestno)


WHY does the following not, then, delete those rows now moved into the new table OUT of the arrest table????:


Delete from dbo.arrest t1
WHERE arrestno NOT IN (SELECT arrestno FROM newgcsowarrants t2 WHERE t2.arrestno=t1.arrestno)

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/08/2012 :  20:52:21  Show Profile  Reply with Quote
And likewise this approach does not work either:


Delete from dbo.arrest (Select * FROM dbo.arrest t1
WHERE arrestno IN newgcsowarrants)

Help. Please?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 04/08/2012 :  23:27:40  Show Profile  Reply with Quote
try

Delete t1 from dbo.arrest t1
WHERE arrestno NOT IN (SELECT arrestno FROM newgcsowarrants t2 WHERE t2.arrestno=t1.arrestno)

or simply

Delete from dbo.arrest 
WHERE arrestno NOT IN (SELECT arrestno FROM newgcsowarrants )


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

WJHamel
Aged Yak Warrior

USA
614 Posts

Posted - 04/10/2012 :  09:22:00  Show Profile  Reply with Quote
Thanks. This was one of those things that i "knew" which i forgot i "knew". Thanks for the nudge.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 04/10/2012 :  15:24:41  Show Profile  Reply with Quote
np

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000