left join 中on和where的讲解

来源:互联网 发布:詹姆斯哈登数据 编辑:程序博客网 时间:2024/05/18 00:52
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";
0 0
原创粉丝点击