一、問題:查詢結果無法顯示test1 的全部數據
SELECT *
FROM test1 a
left join test2 b on b.name=a.name
where b.createtimelike '%2021-03-09 00:00:00%'
and b.post='Java工程師'
二、解決方案
1、取消where條件,將where改為and即可實現
SELECT *
FROM test1 a
left join test2 b on b.name=a.name
and b.createtimelike '%2021-03-09 00:00:00%'
and b.post='Java工程師'
注意:以上篩選條件都是從b表也就是附表中
2、 如果要篩選主表也就是左表的數據,則需將主表的條件放置在where
SELECT *
FROM test1 a
left join test2 b on b.name=a.name
and b.createtimelike '%2021-03-09 00:00:00%'
and b.post='Java工程師'
where available = 1
注:join on 后邊的條件只針對附表
如果要篩選主表,必須寫在where后
轉自:https://blog.csdn.net/weixin_44195615/article/details/114683063