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
 

 

Update using join on same table.

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

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Wed Jan 02, 2008 6:14 pm    Post subject: Update using join on same table.
Reply with quote

Hi ,

I have to update a column of table 1 for selected records.
Actually its a sort of inner join on table1 and table2. and we have to update colm1 of table1.


Queries used:
1.
Update Table1 A
Set A.Colm1 = 'X'
Where exists
( Select 1 from Table2 B
where B.colm2 = A.colm2 and
A.com1 = 'Y'
)

2.
Update Table1 A
Set A.Colm1 = 'X'
Where A.colm1 = 'Y' and
A.colm2 in
( Select distinct C.colm2
from Table2 B , Table1 C
where B.Colm2 = C.colm2 and
C.colm1 = 'Y'
)

When I ran both above queries in SPUFI, I received -911.
The 1st query is a corellated sub query, so may be its hitting the deadlock state.
In case of 2nd query I am a bit confused. The inner sub query has no relation with outer one.

Do u have any other ideas to resolve this issue.

Thanks,
-Kapil.
Back to top
View user's profile Send private message

hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Thu Jan 03, 2008 12:06 pm    Post subject: Reply to: Update using join on same table.
Reply with quote

I tried to search for this query on google.
I found few links but none seems to be working. It looks like SQL server, MS-Access do have some support for these type of queries.

I am sure there must be something in DB2 also.

Could any one please help ?

Thanks,
-Kapil.
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Fri Jan 04, 2008 12:07 pm    Post subject: Reply to: Update using join on same table.
Reply with quote

Hello guys,

Some good news is here.
The problem is fixed. I used the the first query.
1.
Update Table1 A
Set A.Colm1 = 'X'
Where exists
( Select 1 from Table2 B
where B.colm2 = A.colm2 and
A.com1 = 'Y'
)

This was giving -911 while running via SPUFI. This may be because of Timeout.
When I ran the same query in Batch SPUFI.
It worked absolutely fine.

Thanks,
-Kapil.
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Fri Jan 04, 2008 12:39 pm    Post subject:
Reply with quote

Kapil...Thanks for letting us know the solution... 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 IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am


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