SQL 在第一列 OpenQuery 上不同

SQL Distinct on First Column OpenQuery

我在 SQL Server 2014 中使用 OpenQuery 从 Progress 中检索数据。

这是我的查询:

SELECT *
FROM OPENQUERY(PRG, 'SELECT "cde","dsc" FROM tblCodes') 

它会像这样检索数据:

cde     dsc
===     =====
one     test
one     another
one     value
two     goes
two     here
two     also
three   example

但是,我需要的结果如下所示:

cde     dsc
===     =====
one     test
two     goes
three   example

如何在 OpenQuery 中执行此操作?

在您打开的查询中,您的查询应该如下所示,我建议您将 cde 列作为数字 ID:

 WITH CTE AS (select cde,dsc,
    row_number() over(
                        partition by cde
                        order by cde
                    ) as rn

from tblCodes 
)
select cde,dsc from CTE 
where rn =1

在此处检查执行情况:sqlfiddle