Identify when the last update occurred

I have two tables I need to unite. A table has dates that occur for events.

with date_table as (
select 1 ID_Key,to_date('4/1/2013','mm-dd-yyyy') date_val from dual union all
select 1 ,to_date('4/2/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/3/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/4/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/5/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/6/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/7/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/1/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/2/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/3/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/4/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/5/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/6/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/7/2013','mm-dd-yyyy')  from dual 
)

The other table there when was the last time the ID_Key has been updated

with Update_table as (
select 1 ID_key,to_date('3/12/2013','mm-dd-yyyy') Last_Update from dual union all
select 1 ,to_date('4/5/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('3/1/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/2/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/4/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/6/2013','mm-dd-yyyy') from dual
)

I would get the following table

with end_table as (
select 1 ID_Key,to_date('4/1/2013','mm-dd-yyyy') date_val, to_date('3/12/2013','mm-dd-yyyy') last_Update from dual union all
select 1 ,to_date('4/2/2013','mm-dd-yyyy'), to_date('3/12/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/3/2013','mm-dd-yyyy'), to_date('3/12/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/4/2013','mm-dd-yyyy'), to_date('3/12/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/5/2013','mm-dd-yyyy'), to_date('4/5/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/6/2013','mm-dd-yyyy'), to_date('4/5/2013','mm-dd-yyyy') from dual union all
select 1 ,to_date('4/7/2013','mm-dd-yyyy'), to_date('4/5/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/1/2013','mm-dd-yyyy'), to_date('3/1/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/2/2013','mm-dd-yyyy'), to_date('4/2/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/3/2013','mm-dd-yyyy'), to_date('4/2/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/4/2013','mm-dd-yyyy'), to_date('4/4/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/5/2013','mm-dd-yyyy'), to_date('4/4/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/6/2013','mm-dd-yyyy'), to_date('4/6/2013','mm-dd-yyyy') from dual union all
select 2 ,to_date('4/7/2013','mm-dd-yyyy'), to_date('4/6/2013','mm-dd-yyyy') from dual 
)

Any suggestions?

Just join, help<=, then="" group="" by,="" and="" grab="" the="">

with date_table like)

Select 1 ID_Key, to_date (' 1/4/2013 ','mm-dd-yyyy') date_val of all the double union

Select 1, to_date (' 4/2/2013 ','mm-dd-yyyy') of all the double union

Select 1, to_date (' 4/3/2013 ','mm-dd-yyyy') of all the double union

Select 1, to_date (' 4/4/2013 ','mm-dd-yyyy') of all the double union

Select 1, to_date (' 4/5/2013 ','mm-dd-yyyy') of all the double union

Select 1, to_date (' 4/6/2013 ','mm-dd-yyyy') of all the double union

Select 1, to_date (' 4/7/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 1/4/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 4/2/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 4/3/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 4/4/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 4/5/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 4/6/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 4/7/2013 ','mm-dd-yyyy') of double

), Update_table as)

Select 1 ID_key, to_date('3/12/2013','mm-dd-yyyy') Last_Update in double union

Select 1, to_date (' 4/5/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 3/1/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 4/2/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 4/4/2013 ','mm-dd-yyyy') of all the double union

Select 2, to_date (' 4/6/2013 ','mm-dd-yyyy') of double

)

Select dt.id_key, dt.date_val,.

Max (UT.last_update) last_update

of date_table dt.

update_table ut

where dt.id_key = ut.id_key

and ut.last_update<=>

Dt.id_key group, dt.date_val

order of dt.id_key, dt.date_val

/

ID_KEY DATE_VAL LAST_UPDATE

---------- ----------- -----------

1-01 - apr - 2013 12-mar-2013

1-02 - apr - 2013 12-mar-2013

1 03-Apr-2013 12 - mar - 2013

1-04 - apr - 2013 12-mar-2013

1-05 - apr - 2013 05 - apr - 2013

1-06 - apr - 2013 05 - apr - 2013

1-07-Apr-2013 05-apr-2013

2-01 - apr - 2013 01-mar-2013

2-02 - apr - 2013 02 - apr - 2013

2 03-Apr-2013 02-apr-2013

2-04 - apr - 2013 04 - apr - 2013

2-05 - apr - 2013 04 - apr - 2013

2-06 - apr - 2013 06 - apr - 2013

2 07-Apr-2013 06-apr-2013

14 selected lines.

Tags: Database

Similar Questions

Maybe you are looking for

  • How to style 404 pages, etc. ?

    I tried to comb the 404 pages that I get when I - type an invalid URL - have an internet connection problem - etc. Unfortunately, it seems that these 404 pages are not stored as about: pages so that it does not seem as simple to Stylize. Is it possib

  • OTP-S390 - issues with Amazon instant video bonus?

    For 2 weeks now, I think that after the update to the newest firmware, I have massive problems play via the video player Sony Bluray with Amazon premium instant stuff. I did some troubleshooting and I came to the conclusion that it is either the cabl

  • Watch on the A1 cell

    Has anyone ever answer on what 'sleep of the cell' is on the A1 motorway and why he uses so the battery?

  • Vista - Error Code: 0 X 80072726 (Windows Update Service does not start)

    When I run Windows Update it says that it is impossible to connect to the service because the service is not running. When I go into the Services to start the Windows Update service, it says: Windows could not start the Windows Update service on Loca

  • HP 5531:5531 want do not print on mac

    I can't send or .pdf documents to print. I get blank pages when I print from my Mac.