一、(Oracle中已驗證OK)
left join
(select l.* from
(select RealName,CompanyId,row_number() over (partition by CompanyId order by id desc) as rownum1 from vm_User WHERE IsAdmin=1) l
where l.rownum1 = 1 ) w
二、left join (select MAX(RealName),CompanyId, from vm_User GROUP BY CompanyId) W
三、
用OUTER APPLY
select b.* FROM a表 a
OUTER APPLY
(select TOP(1) * from b表 WHERE [Name] = a.[AName] ORDER BY BNo desc) b
原文链接:https://blog.csdn.net/sinat_36500530/article/details/105116381
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明:sql Left Join 右表取一条数据,三种方式 出自老鄢博客 | 欢迎分享