Use Inner join for multi-table join queries

Source: Internet
Author: User

Query the four tables aspnet_membership, aspnet_users, users, and userroles.

1. Do not use inner join for four table join queries

Declare @ username nvarchar (100) <br/> declare @ userpwd nvarchar (100) <br/> set @ username = 'admin' <br/> set @ userpwd = 'Password' <br/> select * From aspnet_membership AM, aspnet_users Au, users U, userroles ur where am. userid = au. userid and <br/> au. username = u. username and U. userid = Ur. userid <br/> and U. username = @ username and AM. password = @ userpwd and Ur. roleid = 0

2. Join a four-table join query using inner

Declare @ username nvarchar (100) <br/> declare @ userpwd nvarchar (100) <br/> set @ username = 'admin' <br/> set @ userpwd = 'Password' <br/> select * from (aspnet_membership inner join aspnet_users on aspnet_membership.userid = aspnet_users.userid) <br/> Inner join users on aspnet_users.username = users. username) Inner join userroles on users. userid = userroles. userid) <br/> where users. username = @ username and aspnet_membership.password = @ userpwd and userroles. roleid = 0

 

The preceding query statement can be used to query the results of the specified username and password with the role roleid = 0.

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.