大家好我試圖實現下面的查詢返回兩個表基於給定的條件的結果。如何把正確的查詢到達預期的輸出?使用類似的查詢來獲得所需的輸出跨兩個表
SELECT * FROM bw_tempclientdetails
where companyname like '%fff%'
not in (SELECT * FROM bw_clientallocation where companyname like '%fff%');
大家好我試圖實現下面的查詢返回兩個表基於給定的條件的結果。如何把正確的查詢到達預期的輸出?使用類似的查詢來獲得所需的輸出跨兩個表
SELECT * FROM bw_tempclientdetails
where companyname like '%fff%'
not in (SELECT * FROM bw_clientallocation where companyname like '%fff%');
使用join < --follow鏈接
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%');
希望它能幫助。祝你好運。
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%');
這種解決方案看起來非常簡單,感謝花花公子 –
我很高興如果我幫助。祝你好運;) –
非常感謝你這個解決方案幫助 –
不客氣..祝你的工作.. :) – sailhenz