Mysql 使用like查询跨两个表获得所需的输出
大家好,我正在尝试实现下面的查询,根据给定的条件从两个表返回结果。如何进行正确的查询以获得预期的输出Mysql 使用like查询跨两个表获得所需的输出,mysql,hibernate,Mysql,Hibernate,大家好,我正在尝试实现下面的查询,根据给定的条件从两个表返回结果。如何进行正确的查询以获得预期的输出 SELECT * FROM bw_tempclientdetails where companyname like '%fff%' not in (SELECT * FROM bw_clientallocation where companyname like '%fff%'); 使用使用 select t1.* from ( SELECT * FROM bw_tempclient
SELECT * FROM bw_tempclientdetails
where companyname like '%fff%'
not in (SELECT * FROM bw_clientallocation where companyname like '%fff%');
使用使用
select t1.* from (
SELECT * FROM bw_tempclientdetails
where companyname like '%fff%' ) as t1
left join (SELECT * FROM bw_clientallocation where companyname like '%fff%') as t2
on t1.companyname = t2.companyname
where t2.companyname is null
SELECT * FROM bw_tempclientdetails
where companyname like '%fff%' and companyname
not in (SELECT companyname FROM bw_clientallocation where companyname like '%fff%');
SELECT *
FROM bw_tempclientdetails bw_temp
LEFT JOIN bw_clientallocation bw_client
ON bw_temp.companyname = bw_client.companyname -- this is just an identifier or link between the tables
WHERE bw_client.company LIKE '%fff%'
AND (bw_temp.companyname LIKE '%fff%' AND bw_client.company LIKE '%fff%');