Highest per each group
It's hard to show my actual table and data here so I'll describe my problem with a sample table and data: create table foo(id int,x_part int,y_part int,out_id int,out_idx text); insert into foo values (1,2,3,55,'BAK'),(2,3,4,77,'ZAK'),(3,4,8,55,'RGT'),(9,10,15,77,'UIT'), (3,4,8,11,'UTL'),(3,4,8,65,'MAQ'),(3,4,8,77,'YTU'); Following is the table foo : id x_part y_part out_id out_idx -- ------ ------ ------ ------- 3 4 8 11 UTL 3 4 8 55 RGT 1 2 3 55 BAK 3 4 8 65 MAQ 9 10 15 77 UIT 2 3 4 77 ZAK 3 4 8 77 YTU I need to select all fields by sorting the highest id of each out_id . Expected output: id