1.on 后面添加關聯條件 where 添加的是添加查詢
這個是一個左查詢 使用的是 select a和b表的關聯條件查出來的結果再去where 條件查詢
select * from event a LEFT JOIN event_time b on a.event_id=b.event_id where a.event_id=2 and a.event_name='吃'
這是on后面添加的and條件:相當於a 表帶上a.event_name='吃' 的結果 才去與 b表去關聯查詢
區別:1.where時a表數據=5,關聯之后數據是5條與b表關聯
2.on and 時 a表數據=5 加上 and 那么a表數據為3條去和b表去關聯查詢
select * from event a LEFT JOIN event_time b on a.event_id=b.event_id and a.event_name='吃'
總結:on后面的and是關聯條件,select * from a where a.event_name='吃'和b表去關聯
如果是where就變成了 select * from a 和b表去關聯之后的數據去where 條件。。。