Left join (external join) SQL statement

Source: Internet
Author: User
Assume that the table structure is: user_info table: role_info table: to query some data from the user_info table and role_info table, for example, when logging on to the system, in addition to the login name and password, you can also query additional information, such as user permissions, which may be connected. Here we use the left join: the SQL statement is as follows: selectu. *, r. role_name, r. right_idfrom (SELECT * F suppose the structure of the table is:

User_info table:

Role_info table:

To query some data from the user_info and role_info tables, for example, when logging on to the system,

In addition to the login name and password, you can also query additional information, such as user permissions, which may be connected.

Use left join here:

The SQL statement is as follows:

Select u. *, r. role_name, r. right_id from (SELECT * FROM user_info WHERE login_name = # login_name # AND password = # password #) AS uleft outer join role_info r on u. role = r. role_code
 

<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.