求SQL语句 过滤重复记录 只显示一条

2024-11-23 10:59:46
推荐回答(3个)
回答1:

select distinct a, b from tb
-- or
select *
from tb tb_a
where not exists (
select 1
from tb tb_b
where tb_a.a = tb_b.a
and tb_a.b = tb_b.b
and tb_a.c < tb_b.c
)

回答2:

select A, B, C
FROM tab t1
WHERE Not exists(select 1 from tab where t1.A = A and t1.B= B and c > t1.c)

回答3:

select * from TableName tn where A=(select top 1 from TableName tn1 where tn1.A=tn.A) and b=(select top 1 from TableName tn1 where tn1.b=tn.b)