
Interesting SQL
All,
I need to write SQL to update one of the description2 column in table A.
Here is the scenario
Create table test
(code varchar2(100),
fld1 varchar2(100),
fld2 varchar2(100),
fld3 varchar2(100),
fld4 varchar2(100),
upcfld varchar2(12),
id number,
desc1 varchar2(100),
desc2 varchar2(100))
Suppose upcfld has value '3' and it has 4 rows with different data in fields. Is it possible to update desc2 based on following conditions? The conditions are :
* If all the fld1..fld4 are same for all rows then desc2 = desc1 of the row which has max(Id)  Simple one!!!
* If any of the fld1...fld4 are different for each row then desc2 = desc1 of each row.
* if fld1..fld4 are same for first two records then desc2 = desc1 of row which has max(ID), but if the third row matches with first then desc2 of third row = desc1 of row 1 and 2 whichever has max(id)
* And so on.......
Is it possible to construct this in SQL? Appreciate your reply!
Let me know if this is clear or need more explaination.

========
if fld1..fld4 are same for first two records then desc2 = desc1 of row which has max(ID), but if the third row matches with first then desc2 of third row = desc1 of row 1 and 2 whichever has max(id)
* And so on.......
==========
In RDBMS, there is no concept called two records and third row.
Tamil