已知有两张表信息为
TB1
(
ID
NAME
)
TB2
(
ID
TB1ID
)现在我要查询出TB1的ID 通过 like % % 然后。在TB2中有很多tb1ID(不重复) 查询过滤掉TB2中存在的TB1 ID
TB1
(
ID
NAME
)
TB2
(
ID
TB1ID
)现在我要查询出TB1的ID 通过 like % % 然后。在TB2中有很多tb1ID(不重复) 查询过滤掉TB2中存在的TB1 ID
我先要从TB1中查询出所有有关的ID在把 TB2中有相关的ID过滤掉,剩下的TB1中的ID就是我要的结果了
select * from tb2 t where not exists
(select 1 from tb1 where id =t.id )
select * from tb1 where id like '% ...%' ---加你的like 条件
and id not in(selct id from tb2)
select * from tb1 t where not exists
(select 1 from tbt where id =t.id )
select * from (
select * from tb1 t where not exists
(select 1 from tbt where id =t.id )
) A
where A.id like '% ...%' ---加你的like 条件
(SELECT ID FROM TB1 EXCEPT SELECT ID FROM TB2)
AND NAME LIKE '%...%'