Sql Query to get the record what has the max id number for each type
问题 I have a table in sql server. It has a pid field used as a primary key and a field called deviceid that has a device name. example: pid deviceid field3 field4 1 Device1 test test 2 Device2 test2 test2 3 Device1 test3 test3 4 Device2 test4 test4 For a query, i need select * from the table where the pid is the max per device. Example result: pid deviceid field3 field4 3 Device1 test3 test3 4 Device2 test4 test4 Im not sure how do do this. Any one have any ideas? The closest i got was: Select