Re: MAX()

From: Paul Quenneville <paulq_at_home.com>
Date: Wed, 31 Oct 2001 04:00:21 GMT
Message-ID: <pHKD7.119438$5h5.48007399_at_news3.rdc2.on.home.com>


Yup.

update table1 a
set col_A = (select col_B from table2 b

                   where key=a.key
                   and col_z = (select max(col_z) from table2
                    where key=b.key))

Note this assumes there is a matching key in table2 for every record in table1
or you could add

where key in (select key from table2)

otherwise col_A will get set to null where there is no matching record.

"Anthony Pontier" <apontier_at_hotmail.com> wrote in message news:6uFD7.54926$6i7.7453352_at_e420r-atl1.usenetserver.com...
> Hello,
>
> I have a column in a table that I want to update from another table, the
> problem is the update from table has more than one row that matches the
keys
> of my update to table, the update from table has a column that keeps track
> of the number of entries in this table for each set of keys from the
update
> to table.
>
> I want to update table1.col_A with the value in table2.col_B from the row
> that has the MAX(table2.col_Z).
>
> Make sense ?
>
> Thanks,
>
> Tony P.
>
>
>
>
Received on Wed Oct 31 2001 - 05:00:21 CET

Original text of this message