If I understood your question correctly then here's your answerSelect a.*, Null Date_difffrom xxxTest aInner Join ( Select Min(CID) CID, CType from xxxTest Group by CType ) bon a.CID = b.CIDUnionSelect a.*, DATEDIFF(day, ExpDate, getdate())from xxxTest aInner Join ( Select Min(CID) CID, CType from xxxTest Where CID not in ( Select Min(CID) from xxxTest ) Group by CType ) bon a.CID = b.CIDGroup By a.CID, a.CType, StartDate, a.ExpDate, UpdatedDatehaving DATEDIFF(day, a.ExpDate, getdate()) > 25Order by a.CType, a.CID
RegardsNIf you want your computer to be faster then throw it out of the window.