Sql server 2012 使用distinct关键字返回链接服务器中的无效行
我从SQL server中的一个查询中得到了一些奇怪的结果,但我无法计算出来。 问题是Sql server 2012 使用distinct关键字返回链接服务器中的无效行,sql-server-2012,distinct,linked-server,Sql Server 2012,Distinct,Linked Server,我从SQL server中的一个查询中得到了一些奇怪的结果,但我无法计算出来。 问题是 select ref5 from t_wholesale_history left outer join AP21..AP21.REFTBL on reftbl.tblname = 'SOrder' and reftbl.rg_ord = 5 left outer join AP21..AP21.REFCODE on refcode.co
select
ref5
from
t_wholesale_history
left outer join
AP21..AP21.REFTBL on
reftbl.tblname = 'SOrder'
and reftbl.rg_ord = 5
left outer join
AP21..AP21.REFCODE on
refcode.code = t_wholesale_history.ref5
and refcode.rgidx = reftbl.rgidx
and refcode.active = 1
where
t_wholesale_history.ref5 is not null
and refcode.rcidx is null
它在远程数据库中查找并列出REF5不存在的所有记录。上面的查询返回0行,这是正确的。
现在,如果我将select ref5更改为select distinct ref5,将得到5行!
为什么使用distinct这个词会返回行?它返回的行甚至不是正确的行,所以这对我来说没有意义
不幸的是,由于远程服务器的复杂性,我无法提供这方面的详细信息,但我猜我得到这些结果的事实与远程服务器有关
有什么想法吗?这对你没有帮助,但我很好奇。如果您使用分组方式而不是DISTINCT,会发生什么?好问题。它返回与使用distinct相同的结果。