Interesting SQL
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Interesting SQL

Hybrid View

  1. #1
    Join Date
    Nov 2004
    Posts
    5

    Interesting SQL

    All,

    I need to write SQL to update one of the description-2 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.

  2. #2
    Join Date
    May 2000
    Location
    ATLANTA, GA, USA
    Posts
    3,135
    ========
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width