1 mysql JOIN 查询
使用join查询金瓶梅这本书出版社的名字
MariaDB [orm]> select * from book;
+
| nid | title | publishDate | price | publish_id |
+
| 1 | 红楼梦 | 2001-04-01 | 200.00 | 1 |
| 2 | 西游记 | 2001-04-01 | 200.00 | 1 |
| 3 | 水浒传 | 2001-04-01 | 200.00 | 1 |
| 4 | 红楼梦 | 2001-04-01 | 200.00 | 1 |
| 5 | 西游记 | 2001-04-01 | 200.00 | 1 |
| 6 | 水浒传 | 2001-04-01 | 200.00 | 1 |
| 7 | 金瓶梅 | 2001-04-01 | 200.00 | 1 |
| 8 | 金瓶梅1 | 2001-04-01 | 200.00 | 1 |
| 9 | 金瓶梅2 | 2001-04-01 | 200.00 | 1 |
| 10 | 金瓶梅3 | 2001-04-01 | 200.00 | 1 |
| 11 | 金瓶梅3 | 2001-04-01 | 200.00 | 1 |
+
11 rows in set (0.001 sec)
MariaDB [orm]> select * from publish;
+
| nid | name | city | email |
+
| 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 2 | 河北出版社 | 河北 | wangze@163.com |
| 3 | 人民出版社 | 北京 | 15532634791@163.com |
| 4 | 河北出版社 | 河北 | wangze@163.com |
+
4 rows in set (0.001 sec)
MariaDB [orm]> select * from book inner join publish on book.publish_id = publish.nid;
+
| nid | title | publishDate | price | publish_id | nid | name | city | email |
+
| 1 | 红楼梦 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 2 | 西游记 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 3 | 水浒传 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 4 | 红楼梦 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 5 | 西游记 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 6 | 水浒传 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 7 | 金瓶梅 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 8 | 金瓶梅1 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 9 | 金瓶梅2 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 10 | 金瓶梅3 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
| 11 | 金瓶梅3 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
+
11 rows in set (0.001 sec)
MariaDB [orm]> select * from book inner join publish on book.publish_id = publish.nid where book.title='金瓶梅';
+
| nid | title | publishDate | price | publish_id | nid | name | city | email |
+
| 7 | 金瓶梅 | 2001-04-01 | 200.00 | 1 | 1 | 人民出版社 | 北京 | 15532634791@163.com |
+
1 row in set (0.001 sec)
MariaDB [orm]> select publish.name from book inner join publish on book.publish_id = publish.nid where book.title='金瓶梅';
+
| name |
+
| 人民出版社 |
+
1 row in set (0.001 sec)
|