This will give you the desired result:
SELECT t.ID, t.FedTaxID, t.RegularPay, t.Payperiodnumber FROM tblemployeegrosswagesn1 t INNER JOIN (SELECT MAX(ID) AS MaxId, FedTaxID, Payperiodnumber FROM tblemployeegrosswagesn1 GROUP BY FedTaxID, Payperiodnumber) AS InnerQuery ON t.ID = InnerQuery.MaxId AND t.Payperiodnumber = InnerQuery.Payperiodnumber AND t.FedTaxID = InnerQuery.FedTaxID WHERE t.FedTaxID = '562545366';
I am intrigued by the published link newtover; In this case, however, you need the maximum identifier for each payperiodnumber, so you will have to adapt this a bit more. It will look something like this:
SELECT t.Id, t.FedTaxId, t.RegularPay, t.Payperiodnumber FROM tblemployeegrosswagesn1 t LEFT JOIN tblemployeegrosswagesn1 t1 ON (t.FedTaxId = t1.FedTaxId AND t.Payperiodnumber = t1.PayperiodNumber AND t.id < t1.id) WHERE t1.ID IS NULL AND t.FedTaxId = '562545366'
It is much easier to read. Many thanks to @BillKarwin for the neat set-based solution. Thank you for the opportunity to learn a new (and better if the link is placed) way to do something.
source share