• You might try running the code before making pronouncements like that. 😉

    I'm looking at the following results on my screen right now.

    Status State Name

    Pending Nebraska ABC

    Active NULL PQR

    The WHERE clause dictates which records to include, and it contains an OR. So, if the state is not null, the row is included OR ,if there is only one row for that status, the row is included. Maybe it will make more sense to you this way. It produces identical results.

    where

    state is not null

    OR

    -- where

    status in (select status from @sample group by status having count(*) = 1)

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills