Possible Duplicate:
Retrieving the last record in each group
Hi all i am having my table data as follows
ID FedTaxID RegularPay Payperiodnumber
1 562545366 500 1
2 562545366 501 1
3 562545366 5000 2
I would like to get my data as follows
ID FedTaxID RegularPay Payperiodnumber
2 562545366 501 1
3 562545366 5000 2
I tried some thing like as follow but i am not getting the required result
select max(id) ID,regularpay,fedtaxid,payperiodnumber
from tblemployeegrosswagesn1 where fedtaxid="562545366"
group by payperiodnumber
having count(*) >= 1;
Can any one help me
This should give you the desired result:
I am intrigued by the link newtover posted; In this instance, though, you want the max id per payperiodnumber so you’ll have to adapt that a bit more. It will look something like:
Which is much simpler to read. Many thanks to @BillKarwin for a neat set based solution. Thanks for the chance to learn a new (and better given the link posted) way of doing something.