首页 > 解决方案 > SQL Server 多连接

问题描述

谁能解释这个查询有什么问题?

select A.*
   from GDPApplication A,
        (select top(e.ToDate) *
         from EducationalQualification e
         where e.Id = A.Id
         order by e.ToDate desc
       ) B left outer join
       EnglishTest eng on A.Id = eng.FKApplicationId

标签: sqlsql-serverdatabase

解决方案


TOP子句需要数字参数,例如TOP (1)为了获取 N.. 根据ordering定义的顶部位置的行数

select A.*
from GDPApplication A cross apply (
         select top (1) e.ToDate,  *
         from EducationalQualification e
         where e.Id = A.Id
         order by e.ToDate desc
       ) B left outer join
       EnglishTest eng on A.Id = eng.FKApplicationId

推荐阅读