Tutorial: MySQL multi-table operations and batch processing method _ MySQL

Source: Internet
Author: User
Tutorial: MySQL multi-table operations and batch processing methods multi-table operations

Multiple tables may exist in a database, which are associated with each other. We will continue to use the previous example. The preceding table contains basic information about an employee, such as name, gender, date of birth, and place of birth. Create another table to describe the articles published by employees, including the author's name, article title, and publication date.

1. view the contents of mytable in the first table.

Mysql> select * from mytable;
+ ---------- + ------ + ------------ + ----------- +
| Name | sex | birth | birthaddr |
+ ---------- + ------ + ------------ + ----------- +
| Abccs | f | 1977-07-07 | china |
| Mary | f | 1978-12-12 | usa |
| Tom | m | 1970-09-02 | usa |
+ ---------- + ------ + ------------ + ----------- +

2. create the second table title (including the author, article title, and publication date)

Mysql> create table title (writer varchar (20) not null,
-> Title varchar (40) not null,
-> Senddate date );

Add a record to the table. the contents of the last table are as follows:

Mysql>
Select * from title;
+ -------- + ------- + ------------ +
| Writer | title | senddate |
+ -------- + ------- + ------------ +
| Abccs | a1 | 2000-01-23 |
| Mary | b1 | 1998-03-21 |
| Abccs | a2 | 2000-12-04 |
| Tom | c1 | 1992-05-16 |
| Tom | c2 | maid |
+ -------- + ------- + ------------ +
5 rows in set (0.00sec)

3. multi-table query

Now we have two tables: mytable and title. Using these two tables, we can perform a combined query: for example, we want to query the name, gender, and article of the author abccs:

Mysql> SELECT name, sex, title FROM mytable, title
-> WHERE name = writer AND name = 'abccs ′;
+ ------- + ------ + ------- +
| Name | sex | title |
+ ------- + ------ + ------- +
| Abccs | f | a1 |
| Abccs | f | a2 |
+ ------- + ------ + ------- +

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.