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
 
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 Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm
No new posts PC (UTF-8) -> z/OS (EBCDIC) -> ... prino All Other Mainframe Topics 4 Fri Sep 01, 2017 1:47 am

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