select * from tableName a where not exists(select 1 from tableName where NAMES=a.NAMES AND A.ID<ID)
select ltrim(ID)+Names as col from tb
if object_id('tb') is not null drop table tb go create table tb([ID] int,[NAMES] varchar(10)) insert tb select 1,'aa' union all select 2,'bb' union all select 3,'aa' union all select 4,'bb' union all select 5,'aa' union all select 6,'bb' union all select 7,'aa' go select ltrim(ID)+Names as col from tb /* col ---------------------- 1aa 2bb 3aa 4bb 5aa 6bb 7aa (7 行受影响) */
FROM tb
ltrim(id)+NAMES
from
tb
select * from tableName a where not exists(select 1 from tableName where NAMES=a.NAMES AND A.ID<ID)
go
create table tb([ID] int,[NAMES] varchar(10))
insert tb select 1,'aa'
union all select 2,'bb'
union all select 3,'aa'
union all select 4,'bb'
union all select 5,'aa'
union all select 6,'bb'
union all select 7,'aa'
go
select ltrim(ID)+Names as col from tb
/*
col
----------------------
1aa
2bb
3aa
4bb
5aa
6bb
7aa
(7 行受影响)
*/