Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Deleting records from one table with multiple conditions

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

New User


Joined: 17 Sep 2008
Posts: 75
Location: bangalore

PostPosted: Fri Nov 07, 2008 2:50 pm    Post subject: Deleting records from one table with multiple conditions
Reply with quote

Hi Friends,

It would be really great if some body help me to resolve the following problem.

I have two tables as follows
Table A
Code:
ColA1,ColA2,ColA3,COLA4,COLA5

Table B
Code:
ColB1,ColB2,ColB3,COLB4,COLB5 ...till COLB10

i need to write a delete query which should delete the records from TableA with the following conditions.
Code:
ColA1 = ColB1
ColA2 = ColB2
ColA3 = ColB3

I tried to use INNER JOIN but failed and got -199 SQLCODE for JOIN keyword.


Thanks & Regards,
Mallik
Back to top
View user's profile Send private message

anandinmainframe

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Fri Nov 07, 2008 3:20 pm    Post subject: Reply to: Deleting records from one table with multiple cond
Reply with quote

Hi,
DELETE FROM Table A
where ColA1 = ColB1
and ColA2 = ColB2
and ColA3 = ColB3
will do a favour
Back to top
View user's profile Send private message
mallik4u

New User


Joined: 17 Sep 2008
Posts: 75
Location: bangalore

PostPosted: Fri Nov 07, 2008 3:32 pm    Post subject:
Reply with quote

Hi,

Thanks for the reply!!
But I have a question
How will you get ColB1, ColB2 and ColB3?


Regards,
Mallik
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Nov 07, 2008 3:40 pm    Post subject:
Reply with quote

[quote=malik]
I tried to use INNER JOIN but failed and got -199 SQLCODE for JOIN keyword.
[/quote]
Can you post your join query?

[quote=anand]
DELETE FROM Table A
where ColA1 = ColB1
and ColA2 = ColB2
and ColA3 = ColB3
will do a favour
[/quote]
will not work ColB1 ColB2 ColB3 are not actual values (literal here i mean)
It should be matched using join
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2285
Location: @my desk

PostPosted: Fri Nov 07, 2008 3:41 pm    Post subject:
Reply with quote

Anand,

The OP is trying to join Table A and Table B and it's not a single table.
Back to top
View user's profile Send private message
mallik4u

New User


Joined: 17 Sep 2008
Posts: 75
Location: bangalore

PostPosted: Fri Nov 07, 2008 3:46 pm    Post subject:
Reply with quote

Hi,

I have got the answer to my query from following IBM site

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db2.doc.apsg/bjnqsubq1002042.htm
Following query wii work
Code:
DELETE FROM TableA
  WHERE (ColA1, ColA2,COlA3) IN (SELECT ColB1, ColB2,COlB3
                               FROM TableB);

Guys thanks for the help!!!

Edited: Please use BBcode when You post some code, that's rather readable...Anuj
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2285
Location: @my desk

PostPosted: Fri Nov 07, 2008 3:52 pm    Post subject:
Reply with quote

Mallik,

Thanks for posting the solution. icon_biggrin.gif
Back to top
View user's profile Send private message
anandinmainframe

Active User


Joined: 31 May 2007
Posts: 171
Location: India

PostPosted: Fri Nov 07, 2008 4:07 pm    Post subject: Reply to: Deleting records from one table with multiple cond
Reply with quote

sorry i have forgetten that.
Back to top
View user's profile Send private message
r2k1984

New User


Joined: 21 Jun 2005
Posts: 69
Location: chennai

PostPosted: Tue Nov 11, 2008 11:36 am    Post subject:
Reply with quote

The above query can be modified in to

DELETE FROM TableA ,TableB
WHERE (ColA1= ColB1,
ColA2=ColB2,
ColA3=COlB3);
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Nov 11, 2008 11:41 am    Post subject:
Reply with quote

r2k1984 wrote:
The above query can be modified in to

DELETE FROM TableA ,TableB
WHERE (ColA1= ColB1,
ColA2=ColB2,
ColA3=COlB3);


This query does not work. That is the conclusion of this discussion.

The query which works has already been posted.
Back to top
View user's profile Send private message
r2k1984

New User


Joined: 21 Jun 2005
Posts: 69
Location: chennai

PostPosted: Tue Nov 11, 2008 12:01 pm    Post subject:
Reply with quote

Small modification to the query

DELETE FROM TableA ,TableB
WHERE (TABLEA.ColA1= TABLEA.ColB1,
TABLEA.ColA2=TABLEB.ColB2,
TABLEA.ColA3=TABLEB.COlB3);

This will surely works
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Nov 11, 2008 12:53 pm    Post subject:
Reply with quote

Did you test this query?
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 Merging 2 records at multiple rows wi... Bijesh DFSORT/ICETOOL 1 Wed Dec 06, 2017 1:50 am
No new posts Increment number for every group of r... srajendran2 DFSORT/ICETOOL 7 Thu Nov 09, 2017 10:31 pm
No new posts Matching and unmatched records!! Vignesh Sid SYNCSORT 3 Thu Nov 09, 2017 11:22 am
No new posts Formatting multiple records to a sing... Vignesh Sid SYNCSORT 3 Tue Nov 07, 2017 12:22 pm
No new posts Updating multiple counts in trailer!! Vignesh Sid SYNCSORT 4 Mon Nov 06, 2017 1:04 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us