Home > Database > Mysql Tutorial > 左连接(外连接)sql语句

左连接(外连接)sql语句

WBOY
Release: 2016-06-07 17:46:57
Original
3057 people have browsed it

假设表的结构图为:

user_info表:

role_info表:

要从表user_info和表role_info中查询出某些数据,比如在登录系统时,

除了要以登录名和密码来查询信息外,还要查询额外的信息,比如用户的权限,那就可能用到连接。

这里用左连接:

sql语句如下:

select u.*,r.role_name,r.right_id from (SELECT * FROM user_info WHERE login_name=#login_name#  AND password= #password# )AS u
left outer join role_info r  on u.role=r.role_code
Copy after login
 
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template