现象:
sql语句实现连接多张有关联的表查询
解决办法:
1:子查询:
(表中字段一一对应 一张表和另外一张表的一个字段唯一确定一行数据)
select (select (select wname from wcode where wcode = users_weixin.wcode) from users_weixin where wxicode = users_receivewx.wxicode) from users_receivewx
2:左链接
(表中字段可以一对一 也可以一对多)
(1):
select c.wname from users_receivewx a left join users_weixin b on a.wxicode=b.wxicode left join wcode c on b.wcode=c.wcode
(2):
select a.messagetype,a.wcodeid,b.name from alertitem a left join alertwcode b on a.wcodeid=b.id where a.messagetype=1
3:和内效果差不多的连接查询
(1):
select c.wname from users_receivewx a,users_weixin b,wcode c where a.wxicode=b.wxicode and b.wcode=c.wcode
(2):
select a.messagetype,a.wcodeid,b.name from alertitem a,alertwcode b where a.wcodeid=b.id and a.messagetype=1;
版权声明:本文为hcwbr123原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。