且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查表中的每个字段是否是另一个表中字段的子串

更新时间:2023-02-19 11:42:59

对于这种情况使用 NOT EXISTS:

select *
from table1 t1
where not exists
(
  select *
  from table2 t2
  where t2.`table2-name` like concat('%', t1.`table1-name`, '%')
);

顺便说一句:您应该避免使用诸如 table2-name 之类的名称,在这些名称中您需要引号才能使用它们.改用 table2_name 之类的东西.

BTW: You should avoid names like table2-name where you need quotes in order to use them. Use something like table2_name instead.