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";