SQLServer 有3种物理连接:Nested Loop(嵌套循环).Merge Join(合并联接).Hash Join(哈希联接). T-SQL中的inner/left/right/full join等在进行优化的过程中会转换成上面3种物理连接. 1.Nested Loop(嵌套循环) SELECT e.BusinessEntityID FROM HumanResources.Employee AS e INNER JOIN Sales.SalesPerson AS s ON e.Busi…
left join SM_SOLine soline on soline.SO=so.ID and soline.DocLineNo=(select MAX(DocLineNo) from SM_SOLine where so=so.ID) create table #test8( id int, name varchar(50)) drop table #test9create table #test9( id int, name varchar(50)) insert into #t…
--exists 结合 if else 以及 where 条件来使用判断是否有数据满足条件 select * from Class where Name like '%[1-3]班' if (not exists(select * from Class where len(Name)>=5)) select '满足条件' else select '不满足条件' --in not in 用来做范围判断 select * from Student where ClassId in(select Id…
表连接注意left join on与where的区别: select * from dept; select * from emp; select * from emp a right outer join dept b on a.deptno=b.deptno where a.empno is null; select b.deptno,a.* from emp a right join dept b on a.deptno=b.deptno and a.empno is null; 这里注意…