Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
select * from <Yourtable> twhere Dist = (select top 1 dist from <Yourtable> where id = t.id order by Dist)
EDIT:Here is another (2005 way). I don't know which will perform better
select ID ,Postcode ,PUBID ,PubName ,Postcode ,Distfrom ( select ID ,Postcode ,PUBID ,PubName ,Postcode ,Dist ,row_number() over (partition by ID order by Dist) rn from yourTable t ) dwhere rn = 1