一、自关联
引入:省市区三级联动数据
导入外部.sql文件的数据:
从SQLyog选择文件导入并执行SQL语句,导入了三张表(省、市、县区)的数据。
读者需要练习使用省市区数据执行脚本可以打开文末的网盘链接进行下载。
-查询湖南省
select * from provinces where province = '湖南省';
打印
+----+------------+-----------+
| id | provinceid | province |
+----+------------+-----------+
| 18 | 430000 | 湖南省 |
+----+------------+-----------+
1 row in set (0.00 sec)
-查询湖南省下面的市
select * from cities where provinceid = 430000;
打印
+-----+--------+--------------------------------+------------+
| id | cityid | city | provinceid |
+-----+--------+---------