Unix Technical Forum

update qualifying rows from join - plsql noob

This is a discussion on update qualifying rows from join - plsql noob within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Pardon my needing to ask and thanks in advance for any help with this. This query produces some 20k ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 01:04 PM
jobs
 
Posts: n/a
Default update qualifying rows from join - plsql noob

Pardon my needing to ask and thanks in advance for any help with this.

This query produces some 20k rows.

select
an.status,
an.lastdate
hp.key,
hp.termdate
from tabhp hp inner join
taban an on hp.keyi=an.key
where hp.termdate > sysdate
and an.status='done';


taban has one record per key with the CURRENT STATUS.
tabhp has the history of key with many duplicate rows with the same
keys.

the above query returns keys that are in status 'done', that have
history rows with a future dated termdate. I want to correct this by
setting the termdate for all those rows to the lastdate of the CURRENT
STATUS ROW.

so if

taban:

key=123,status=done,lastdate=1/1/2007
key=124,status=active,lastdate=1/2/2007

tabhp
key=123,termdate=1/20/2020
key=123,termdate=1/20/2020
key=124,termdate=1/20/2020

I need an update that will change tabhp as follows:
key=123,termdate=1/1/2007
key=123,termdate=1/1/2007
key=124,termdate=1/20/2020

Thank you!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 01:04 PM
sybrandb@hccnet.nl
 
Posts: n/a
Default Re: update qualifying rows from join - plsql noob

On Thu, 21 Jun 2007 13:24:40 -0700, jobs <jobs@webdos.com> wrote:

>Pardon my needing to ask and thanks in advance for any help with this.
>
>This query produces some 20k rows.
>
>select
> an.status,
> an.lastdate
> hp.key,
> hp.termdate
>from tabhp hp inner join
> taban an on hp.keyi=an.key
>where hp.termdate > sysdate
>and an.status='done';
>
>
>taban has one record per key with the CURRENT STATUS.
>tabhp has the history of key with many duplicate rows with the same
>keys.
>
>the above query returns keys that are in status 'done', that have
>history rows with a future dated termdate. I want to correct this by
>setting the termdate for all those rows to the lastdate of the CURRENT
>STATUS ROW.
>
>so if
>
>taban:
>
>key=123,status=done,lastdate=1/1/2007
>key=124,status=active,lastdate=1/2/2007
>
>tabhp
>key=123,termdate=1/20/2020
>key=123,termdate=1/20/2020
>key=124,termdate=1/20/2020
>
>I need an update that will change tabhp as follows:
>key=123,termdate=1/1/2007
>key=123,termdate=1/1/2007
>key=124,termdate=1/20/2020
>
>Thank you!


update tabhp h
set termdate =
(select termdate
from taban an
where an.key = hp.key)
where exists
(select 'x'
from taban an
where an.key = hp.key)

When is this assingment due?

--
Sybrand Bakker
Senior Oracle DBA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:26 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com