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
 

 

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: 2284
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: 2284
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 Changeman get multiple "Browse C... elixir1986 Compuware & Other Tools 4 Fri Jul 14, 2017 1:48 am
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 16 Thu Jul 13, 2017 2:11 pm
No new posts How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm


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