主表:user,
關聯表:orders,
關聯條件:orders.userid=user.id
篩選條件:orders.「ordername」=『***x』
user left join orders on orders.userid=user.id and orders."ordername"='***x'
user表和orders表的連線主要依靠關聯條件;
對於主表的篩選條件,應該放置在where條件後;
on後面的篩選條件是針對關聯表orders
關聯表的篩選條件,如果放置在on後面,則user和orders的連線順序為:orders表先按條件查詢,然後再和user表連線,即先篩選再連線;如果放置在where後面,則a和b的連線順序為:a與b連線後,再從連線表中篩選,即先連線再篩選;
where後面的條件是對連線後的資料進行篩選。
原文連線:
SQL語法 left join on 多條件
重點 先匹配,再篩選where條件。本文將通過幾個例子說明兩者的差別。表1 product idamount 1100 2200 3300 4400 表2 product details idweight exist222 04441 55506 661單個條件 select from produc...
left join on 和where條件的放置
left join裡面帶and的查詢 select p.pname,p.pcode,s.saletime from product as p left join sales detail as s on s.pcode p.pcode and s.saletime in 2012 07 23 201...
left join on 和where條件的放置
select from tdleft join select case id as sup case id count supervise number from td kcdc case sup info group by case id sup on sup.sup case id td.cas...