select fkey,color from table3 where fkey+convert(varchar(5),sortorder) in (select fkey+convert(varchar(5),max(sortorder)) as 'ord' from table3 group by fkey)HTH.
>fkey color sortorder >----------------------------------- >1 Red 100 >1 White 101 >1 Blue 102 >2 Black 1001 >2 Blue 1002 >3 Purple 101 >3 Yellow 102 >3 Orange 103 >3 Blue 104Now I want a result set with a record for each fkey with the color that has the maximum sortorder for that fkey. My result set should be:
>fkey color >----------------------------------- >1 Blue >2 Blue >3 Blue>
select fkey, max(sortord) from mytable group by fkeybut as soon as I try to add the color field, it has to go into the group by clause, and I just get all the records back. Any easy way to get this in one select?