Here is one way. I created a very simple example based on your "fake" requirments.--create fake tablecreate table #address (addressid int ,clientid int ,address1 varchar(25) ,city varchar(25) ,postalcode varchar(25))--enter fake datainsert #addressselect 1, 1, '12 main st', 'austin', '12345' union allselect 2, 1, '13 main st', 'austin', '12345' union allselect 3, 2, '5 nanjing', 'taibei', '54321' union allselect 4, 2, '12 nanjing', 'taibei', '65432' --get 1st row from groupselect addressid ,clientid ,address1 ,city ,postalcodefrom #address awhere addressid = (select top 1 addressid from #address where clientid = a.clientid order by postalCode desc)drop table #addressoutput:addressid clientid address1 city postalcode ----------- ----------- ------------------------- ------------------------- ------------------------- 2 1 13 main st austin 123454 2 12 nanjing taibei 65432
Be One with the OptimizerTG