select * from table1 left join table2 on table1.id=table2.id where table2.name="name";
left join on 首先是以左表為主表去連線右表生成乙個中間表 然後再有where 語句到生成的中間表中去查詢符合where條件的記錄出來
備註:left join on可以連線好多表
列如:select * from t_s_base_user as a left join user_detail_info as b on b.id=a.id left join t_s_user as c on a.id=c.id left join t_s_role_user as d on d.userid=a.id left join t_s_role as e on e.id=d.roleid where a.username="minadmin";
SQL 中 left join 等用法 和理解
給個通俗的解釋吧.例表aaid adate 1 a1 2 a2 3 a3 表bbid bdate 1 b1 2 b2 4 b4 兩個表a,b相連線,要取出id相同的字段select from a inner join b on a.aid b.bid 這是僅取出匹配的資料.此時的取出的是 1 a1 ...
資料庫left join中on和where條件區別
oracle的left join中on和where的區別 1,說明 oracle資料庫在通過連線兩張或多張表來返回記錄時,都會生成一張中間的臨時表,然後再將這張臨時表返回給使用者。在使用leftjion時,on和where條件的區別如下 1 on條件是在生成臨時表時使用的條件,它不管on中的條件是否...
Left join 中where on 的 區別
left join中where,on區別 table a id,type id type 1 1 2 1 3 2 table b id,class id class 1 1 2 2 sql語句1 select a.b.from a left join b on a.id b.id and a.typ...