语法:FROM table1 LEFT JOIN table2 ON table1.field1 compopr table2.field2
说明:table1, table2参数用于指定要将记录组合的表的名称。
field1, field2参数指定被联接的字段的名称。且这些字段必须有相同的数据类型及包含相同类型的数据,但它们不需要有相同的
名称。
compopr参数指定关系比较运算符:"=", "<", ">", "<=", ">=" 或 "<>"。
例子:
select m1.Matename,MapName,dict.Fieldname,DesinNum,e1.Realname as name1,e2.Realname as name2,ConstrProjName,ChgNum,projdesignmaterial.Savetime,Remarks,projdesignmaterial.ID,projdesignmaterial.ProjID from projdesignmaterial
left join material m1 on projdesignmaterial.MateID = m1.ID
left join dict on projdesignmaterial.Unit = dict.ID
left join employee e2 on projdesignmaterial.ConformID = e2.ID
left join constrproj on projdesignmaterial.ProjID = constrproj.ConstrProjID WHERE projdesignmaterial.ID = '$ID'
高级应用 A和B ,A和C 连接, 在中间也可进行B和C的左连接
SELECT u.mobile,t1.teamname,u.realname,u.address,u.regdate from team_users
left join users u on team_users.userID=u.userid
left join team t1 on team_users.teamid=t1.teamid
left join `match` m1 on t1.matchid=m1.matchidwhere u.usertype=1 and m1.matchid=2
多条件查询框查询