SELECT * FROM A;
SELECT * FROM B;
以上是兩張表的機構sql
SELECT * FROM A LEFT JOIN B ON A.id=b.a_id ;
語句一 : SELECT * FROM A LEFT JOIN B ON A.id=b.a_id AND A.id <3;
語句二: SELECT * FROM A LEFT JOIN B ON A.id=b.a_id WHERE B.id <3;
兩個語句查詢出來的結果是有差別的spa
sql查詢的關鍵字順序爲 from -> where -> group by-> having ->order by3d
left join 是在from範圍的因此先on條件篩選,而後再作left joincode
而where是在left join的結果以後再次篩選blog
語句一(等價於SELECT *FROM A LEFT JOIN (SELECT * FROM B WHERE B.id < 3) b2 ON A.id = b2.a_id;)class
語句二im
使用注意事項:查詢