Database MySQL simple operation (iii)

Source: Internet
Author: User

1.3 Multi-Table query

1.3.1 Connection query:

#内连接:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/06/95/wKiom1m6YKvB6h36AAA-7J4lU9I019.png "title=" Capture. png "alt=" Wkiom1m6ykvb6h36aaa-7j4lu9i019.png "/>

Self-connect query:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/A5/46/wKioL1m6W1jyaIZOAAA98jRzzcI268.png "title=" Capture. png "alt=" Wkiol1m6w1jyaizoaaa98jrzzci268.png "/>

# External Connection

Left OUTER JOIN (can query all records of table name 1, and table name 2 can only find matching records)

List of SELECT property Names from table name 1 left JOIN table name 2 on table name 1. property name 1= table Name 2. property Name 2;

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/06/95/wKiom1m6X8Xike9IAABEwB6Xz5E039.png "title=" Capture. png "alt=" Wkiom1m6x8xike9iaabewb6xz5e039.png "/>

# RIGHT OUTER join (can query all records of table name 2, and table name 1 can only find matching records):

First, insert some values into the right table:

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/A5/46/wKioL1m6XreQYFXQAAA41aW9CNQ404.png "title=" Capture. png "alt=" Wkiol1m6xreqyfxqaaa41aw9cnq404.png "/>

Then make the right outer join query:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/A5/46/wKioL1m6XyCAQLHoAABGAz29w5w844.png "title=" Capture. png "alt=" Wkiol1m6xycaqlhoaabgaz29w5w844.png "/>



1.4 Modifying fields for some records

The previous simple introduction (insert INTO) and check (select * from), here goes on to say change.

1.4.1 Single-table update

The simplest expression is:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/A5/46/wKioL1m6Y7KRusOXAAA47_h_isM549.png "title=" Capture. png "alt=" Wkiol1m6y7krusoxaaa47_h_ism549.png "/>

Add some more restrictions, as follows:

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/06/96/wKiom1m6aNiARFl5AAAjeXrwxK0454.png "title=" Capture. png "alt=" Wkiom1m6aniarfl5aaajexrwxk0454.png "/>

The results are as follows:

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/A5/46/wKioL1m6aYaB7DJpAABBKqts6ek746.png "title=" Capture. png "alt=" Wkiol1m6ayab7djpaabbkqts6ek746.png "/>

1.4.2 Multi-table update

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/A5/47/wKioL1m6cPXQFSPtAAArB_2i1VY823.png "title=" Capture. png "alt=" Wkiol1m6cpxqfsptaaarb_2i1vy823.png "/>

Well, this example doesn't work at all, because we're only associated with SIDS, which can be written separately for two updates.

However, in the case of multiple table updates, if it is related to two tables, such as having a turn-out table and a transfer table have interdependent keys, so that some States are closely related to update together. (It seems to be a good business.)

......

The above results are as follows:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/A5/47/wKioL1m6cuuDqYW4AAA7lmHc9yE371.png "title=" Capture. png "alt=" Wkiol1m6cuudqyw4aaa7lmhc9ye371.png "/>


1.5 Delete

For a detailed MySQL delete operation, you can view the article

Http://www.cnblogs.com/ggjucheng/archive/2012/11/06/2756420.html

Single-table record deletion:

DELETE from table name WHERE conditional expression [ORDER by field][limit record rows]

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/06/98/wKiom1m6h3Cj9a7cAAAU_SrL-Kg316.png "title=" Capture. png "alt=" Wkiom1m6h3cj9a7caaau_srl-kg316.png "/>

The original data is this:

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/06/98/wKiom1m6iGqjq9fAAABgNd6t5m8052.png "title=" Capture. png "alt=" Wkiom1m6igqjq9faaabgnd6t5m8052.png "/>


Database MySQL simple operation (iii)

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.