SQL多表查询

多表连接必须有连接条件,否则结果没有意义

隐式连接和显示内连接

select title,content,name,publish_time
from user u,forum f #给表起⼀个别名,⽅便书写
where u.id = f.uid; 在where写链接条件

select title,content,name,publish_time
from user u,forum f
where u.id = f.uid and name='王琨';

 显式内连接  交集

select username,name,title
 -> from bbs_user a inner join bbs_forum c on c.uid =a.uid
 -> inner join bbs_category b on c.cid = b.cid;

 

表的自身连接

select * from areainfo a,areainfo b where a.pid=b.code and
a.name='⻘河县';

外连接

两张表关联查询根据以哪一张表为主可以分为左外连接和右外连接

select username,r.* from blog_user u left join blog_remark r on
u.uid = r.uid

 

它们的区别是什么?

https://blog.csdn.net/xuanjiewu/article/details/50636465

 

posted @ 2020-06-06 15:21  扣剑书生  阅读(191)  评论(0)    收藏  举报