dbTalk Databases Forums  

Proper Delete From syntax ?

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Proper Delete From syntax ? in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ScottHW
 
Posts: n/a

Default Proper Delete From syntax ? - 08-27-2003 , 09:14 AM






This is a 7.2 database. I am trying to test this, but having resource
troubles, and running out of time. I want to delete rows from
myschema.mytable1, but only the rows that meet the following condition. I
have structured the SQL using a correlated reference. Is this right, or
will I delete more than meets the subquery condition ?


delete from a where
(select a.host_id, a.field2, a.field3, a.field4 from
myschema.mytable1 a,
myschema.mytable2 b
where
a.host_id=b.host_id and a.field2=b.field2 and
b.field3=b.field3 and a.field4=b.field4)


Thanks,
Scott





Reply With Quote
  #2  
Old   
Christian Maslen
 
Posts: n/a

Default Re: Proper Delete From syntax ? - 08-27-2003 , 04:54 PM






Hi Scott,

The correct syntax is:

delete
from myschema.mytable1 a
where exists
(select *
from myschema.mytable2 b
where a.host_id=b.host_id
and a.field2=b.field2
and b.field3=b.field3
and a.field4=b.field4)

If you replace the "delete" with a "select *", you can see exactly
which rows will be deleted before going ahead with the delete. If you
are expecting a large number of rows Select count(*) will tell you how
many rows will be deleted.

Christian.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.