MySQL Three table connection query

Source: Internet
Author: User

Permission table (permission) 10

Field name

Type

Constraints

Describe

AuthorityID

Integer

Pk

NOT NULL

Permission Serial ID PK

Usernameid

Int

NOT NULL

User name ID FK

FunctionID

Integer

NOT NULL

function ID FK

Lookpermission

Int

NOT NULL

Browse

Addpermission

Int

NOT NULL

Add to

Editpermission

Int

NOT NULL

Edit

DeletePermission

Int

NOT NULL

Delete

Checkpermission

Int

NOT NULL

Audit

Againstrcheckpermission

Int

NOT NULL

Anti-Audit

Statementpermission

Int

NOT NULL

Report

Function Module table (functioncomponents) 3

Field name

Type

Constraints

Module Name Description

Functioncpid

Integer

Pk

function ID PK

Fundescribe

Varchar (100)

NOT NULL

Module name

Otherinfo

Varchar (500)

NOT NULL

Note

User table (UserInfo)

Field name

Type

Constraints

Describe

Userno

Integer

Pk

NOT NULL

Permission Serial ID PK

UserName

VARCHAR2 (20)

NOT NULL

User name ID FK

Userpwd

VARCHAR2 (20)

NOT NULL

Browse

Role

VARCHAR2 (20)

NOT NULL

Browse

To query the permissions of a user's corresponding function

At first, I was using a subquery, not implemented

Select Userno, Userinfo.username, Userinfo.userpwd, Fundescribe, Lookpermission, Addpermission, EditPermission, DeletePermission, Checkpermission, Againstrcheckpermission, statementpermission from UserInfo, permission, Functioncomponents

Switch

Select Userno, Userinfo.username, Userinfo.userpwd, Fundescribe, Lookpermission, Addpermission, EditPermission, DeletePermission, Checkpermission, Againstrcheckpermission, statementpermission from UserInfo, permission, Functioncomponents GROUP BY Userno

The same is true!

After that, the three tables are connected in a query

Create View ' userfunpermission ' as

Select Userno, Userinfo.username, Userinfo.userpwd, Fundescribe, Lookpermission, Addpermission, EditPermission, DeletePermission, Checkpermission, Againstrcheckpermission, statementpermission from UserInfo, permission, Functioncomponents

OK!

MySQL Three table connection query

Related Article

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.