Mysql中3表连接

您所在的位置:网站首页 如何将两个链表连接起来显示在一起呢 Mysql中3表连接

Mysql中3表连接

#Mysql中3表连接| 来源: 网络整理| 查看: 265

简要概述 表连接分为等值连接和外连接两种。

外连接又分为:

左连接(left join);

右连接(right join);

全连接(union)

举例

对以下三张表展开连接,分别为stu、cou、tea

stu中,字段为t_id ; t_name ; t_cid

cou 中,字段为 t_cid ; c_name ; t_id

tea中,字段为 t_id ; t_name

 

例1:对三表进行等值连接

语句:select * from stu,cou,tea where stu.t_cid=cou.t_cid and cou.t_id=tea.t_id;

结果:

例2:以cou为主表,对三表进行连接

语句:

select * from cou left join stu on cou.t_cid=stu.t_cid left join tea on cou.t_id=tea.t_id;

 结果:

 例3:对stu和cou两表进行全连接

语句:

select * from cou left join stu on cou.t_cid=stu.t_cid  union select * from cou right join stu on cou.t_cid=stu.t_cid; 

结果:

 以上对表连接进行了简要的介绍和操作的说明,希望对大家有帮助~

See you!



【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3