IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Update using join on same table.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top