a列名,col1
b列名,iden
a的数据1,2,3,4,5,6
b的数据1,2,3,4select col1,iden
from a,b
where col1*=iden
and iden is not null
select col1,iden
from a left join b on (col1=iden)
where iden is not null结果第一句,and iden is not null没起作用,还是有NULL值
第二句就对了
为什么呢
b列名,iden
a的数据1,2,3,4,5,6
b的数据1,2,3,4select col1,iden
from a,b
where col1*=iden
and iden is not null
select col1,iden
from a left join b on (col1=iden)
where iden is not null结果第一句,and iden is not null没起作用,还是有NULL值
第二句就对了
为什么呢
from a left join b on (col1=iden)
AND iden is not null
如果说是执行顺序问题,SQL2000首先执行的是FROM子句,然后到WHERE子句,
第一条是先执行(from a,b) 得到a,b的笛卡尔积
然后执行(where col1*=iden and iden is not null ) 过滤符合出条件的记录
难道说这里会先执行iden is not null 这里的条件,然后再执行col1*=iden 的条件吗?
第二条是先执行(from a left join b on (col1=iden) )
得到a与b左连接后的结果
然后执行(where iden is not null )
这样得到对的结果为什么第一条就不对呢?
具体看执行计划
我问的其实就是为什么(iden is not null)这句没有起到作用?
好吧,我换种问法select col1,iden
from a left join b on (col1=iden)
AND iden is not null 这样是新的连接方式了,为什么这里(iden is not null )没有起作用呢?
难道说这里会先执行iden is not null 这里的条件,然后再执行col1*=iden 的条件吗?
>>>
Yes
2000快速批量删除前N条数据
--前提:只能根据拥有聚集索引的id才能达到准确无误的删除操作
--下面是一个简单的例子
*/
if object_id('tb') is not null drop table tb
go
create table tb (id int)
go
insert tb select 2
union all select 1
union all select 3
go
create index idx1 on tb(id)
go
set rowcount 2
delete a from tb a with(index = idx1)
set rowcount 0
go
select * from tb
go
drop table tb
go