You want to group by the town name, not both the name and code. You almost never want to group by a column you are aggregating, just doesn't make sense to do so.
select t.townname,count(distinct(t.towncode))as total from town t group by t.townname
101percent its working thanks
quote:Originally posted by GilaMonster
That won't work.
That will give you: M1 1 Z1 1 Z1 1
You want to group by the town name, not both the name and code. You almost never want to group by a column you are aggregating, just doesn't make sense to do so.