locked
update based on grouping RRS feed

  • Question

  • User-664207211 posted

    i want to update top 2 records for following condition

    i have table 'Guarantors' with fields AcNo, AcType, GuarantorDate, Status.
    This table contains multiple records for these columns.

    i want to update status for top 2 maximum GuarantorDate for group of AcNo and AcType.

    Following is my group SQl

    select acno,actype,count(AcNo) from Guarantors group by AcNo,AcType

    Monday, May 9, 2011 8:28 AM

Answers

  • User-886123767 posted

    update Guarantors
    SET
    Guarantors.Status = 'Status'
    FROM
    (select TOP 2 acno,actype from Guarantors group by AcNo,AcType) T
    WHERE
    T.acno = Guarantors.acno and  T.AcType = Guarantors.AcType

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 9, 2011 9:20 AM