首页 > 应用开发 > IT综合 > DISTINCT 和 TOP合用的执行顺序
实验:
IF (OBJECT_ID('tempdb..#tmp_a')) IS NOT NULL
DROP table #tmp_a
CREATE table #tmp_a (a int)
insert into #tmp_a select 1
insert into #tmp_a select 2
insert into #tmp_a select 2
insert into #tmp_a select 2
insert into #tmp_a select 3
select * from #tmp_a
SELECT DISTINCT TOP 3 * from #tmp_a
根据以上结果得知:系统先distinct运算再top运算。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/66009/viewspace-874363/ ,如需转载,请注明出处,否则将追究法律责任。