Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Delete after comparing b/w two tables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
chan2004

New User


Joined: 28 Mar 2007
Posts: 16
Location: India

PostPosted: Mon May 05, 2008 12:34 pm    Post subject: Delete after comparing b/w two tables
Reply with quote

Hi,

I want to delete all records from a table A after comparing it with another table,B.
Both tables have same structure.
They have a column called 'name'.
if a row is there that contains a value of 'john' in name field of table A and there is no such value in table B, i need to delete it from table A
how to delete all such rows with one sql command?
will this sql work

DELETE FROM tableA
WHERE
ID = :id
AND
NAME not in
(SELECT NAME FROM tableB)
;

will this delete all rows?
Back to top
View user's profile Send private message

guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Mon May 05, 2008 12:43 pm    Post subject:
Reply with quote

Hello Chan,

I have just viewing ur query but unable to understand why u have used ID Col.

Quote:
DELETE FROM tableA
WHERE
Code:
ID = :id

AND
NAME not in
(SELECT NAME FROM tableB)
;


I think below query is sufficent

Code:
DELETE FROM tableA
WHERE
NAME not in
(SELECT NAME FROM tableB)
;
Back to top
View user's profile Send private message
chan2004

New User


Joined: 28 Mar 2007
Posts: 16
Location: India

PostPosted: Mon May 05, 2008 1:21 pm    Post subject:
Reply with quote

[quote="guptae"]Hello Chan,

I have just viewing ur query but unable to understand why u have used ID Col.

Quote:
DELETE FROM tableA
WHERE
Code:
ID = :id

AND
NAME not in
(SELECT NAME FROM tableB)
;


I think below query is sufficent

thanks ekta for confirming the query
the id is just another condition that i need to check before deleting icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm
No new posts SPUFI -- Joining 3 tables – data in... Sysaron DB2 2 Wed Mar 08, 2017 4:18 am
No new posts To know activities on db2 tables ashek15 DB2 4 Fri Mar 03, 2017 11:23 pm
No new posts ERM-Diagram of SysIBM-Catalog-Tables Auryn DB2 2 Fri Feb 17, 2017 6:22 pm
No new posts JCL to delete component in a package sundaram.naveen Compuware & Other Tools 14 Tue Nov 29, 2016 6:21 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us