• I'm assuming the goal here is the retreive the latest DUESTATUS and COMPSTATUS for each PERSID, and what we have to work with is a table containing one record for each person status update.

    The problem with using GROUP BY for this given scenario is that it may not be as logically consistent and reliable as ranking, when the final result should really be derived from a single record, specifically the last inserted. For example, there may be some cirsumstances where the logical processing status reverts back from 'Overdue' to 'Due' and this is performed by the application as an update but rather a new insert.

    We don't have the DDL of the actual table, but given something like the following, I'd be more inclined to use DENSE_RANK() or ROW_NUMBER() and then apply a filter to get columns from the latest record for each PERSID.

    create table PERSON

    (

    primary key ( PERSID, STATUSUPDATE ),

    PERSID int not null,

    STATUSUPDATE datetime not null

    DUESTATUS varchar(30) not null,

    COMPSTATUS varchar(30) not null

    );

    select PERSID, DUESTATUS, COMPSTATUS

    from (

    select PERSID, DUESTATUS, COMPSTATUS

    , dense_rank() over

    (partition by PERSID

    order by STATUSUPDATE desc) as STATUSRANK

    from PERSON ) R

    where R.STATUSRANK = 1;

    I alternate between GROUP BY and DENSE_RANK() methods depending on the circumstances. Depending on how the records are related, sometimes the final result can't be derived from a single record and must be an aggregated using grouping. Sometimes it just comes down to performance; both may give the same result but one method better leverages the existing primary key and indexes on the table.

    Try both.

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho