Multi-table operations
In a database, there may be multiple tables, all of which are interrelated. We continue to use the previous example. The table previously established contains some basic information about the employee, such as name, sex, date of birth, place of birth. We'll create a table that describes the articles published by the employee, including the author's name, the title of the article, and the date of publication.
1, view the contents of the first table mytable:
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 a second table title (including author, article title, Publication date):
mysql> create table title(writer varchar(20) not null,
-> title varchar(40) not null,
-> senddate date);
Add a record to the table, and the final table reads 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 | 1999-12-12 |
+--------+-------+------------+
5 rows in set (0.00sec)