字段1和字段2 字符字段如果字段1包含字段2, 或字段2包含字段1,或字段1和字段2字符相同 都认为他们字段相同。
比如ab a, b ba , ab ab 都认为相同为什么
select * from k2 a where not exists (select 1 from k1 b where a.字段=b.字段)
改为
select * from k2 a where not exists (select 1 from k1 b where a.字段 like b.字段)等不到正确结果。求正确语句。
比如ab a, b ba , ab ab 都认为相同为什么
select * from k2 a where not exists (select 1 from k1 b where a.字段=b.字段)
改为
select * from k2 a where not exists (select 1 from k1 b where a.字段 like b.字段)等不到正确结果。求正确语句。
select *
from k2 a
where exists(select 1 from k1 b where charindex(b.字段,a.字段)>0 or charindex(a.字段,b.字段)>0 or b.字段=a.字段=)
FROM k2 a
WHERE NOT EXISTS ( SELECT 1
FROM k1 b
WHERE LEFT(a.字段, 1) = LEFT(b.字段, 1) )
drop table k1
go
create table k1
(id int, cname varchar(4))
insert into k1
select 1,'ab' union all
select 2,'b' union all
select 3,'ab' union all
select 4,'abc'
if object_id('k2')is not null
drop table k2
go
create table k2
(id int, cname varchar(4))
insert into k2
select 1,'a' union all
select 2,'ba' union all
select 3,'ab' union all
select 4,'abd'
select * from k2 a where not exists (select 1 from k1 b where a.cname = b.cname)/*
-----------
id cname
1 a
2 ba
*/select * from k2 a where not exists (select 1 from k1 b where a.cname like b.cname)/*
-----------
id cname
1 a
2 ba
*/我这儿测试没问题啊,楼主是结果什么问题?