MYSQL多表查询

多表查询就是从多张表中查找所需数据,并且整合在一起显示出来的意思

多表查询拥有多种实现方式:内连接、外连接、子查询

一、内连接查询——inner join

select ID,city.name,city.population,lifeexpectancy from city,country where id<10 and city.countrycode=country.code;

标准写法:

select ID,city.name,city.population,lifeexpectancy from city inner join country where id<10 and city.countrycode=country.code;


补充:笛卡尔积(由全匹配所导致的问题)

select join1.id,name,city.unit from join1,join2;

二、外连接查询 outer join ,left and right

select ID,city.name,city.population,lifeexpectancy from city LEFT OUT JOIN country

ON id<10 and city.countrycode=country.code limit10;

左右连接的区别就是“以谁为准”

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容