[英]the whole data from tables is not coming via join query in mysql
我正在使用php mysql,有12个表包含学生信息。有3个主表第一个表是注册,第二个是demandraft,第三个是creditcard。demandraft表包含所有信用表表字段但是为空。 现在我想从这三个表中获取整个数据来生成我的xls文件,但是因为在demandraft表中有一些空字段的信用表,所以无法从所有3个表中获取整个记录。 在所有3个表中都有共同的字段。
这是我的连接查询:
$sql = "select * from registration
join programme on registration.id=programme.stuid
join family on registration.id=family.stuid
join address on registration.id=address.stuid
join education on registration.id=education.stuid
join extradetail on registration.id=extradetail.stuid
join workexperience on registration.id=workexperience.stuid
join demanddraft on registration.id=demanddraft.stuid
join payonline on registration.id=payonline.stuid
where (DATE(registration.createddate)>='".$term1."'
AND DATE(registration.createddate)<='".$term2."')";
使用左连接。
select *
from a join b on a.id = b.a_id
不会列出表b中未出现的表格a的行。
select *
from a left join b on a.id = b.a_id
将。
当使用多个表链接其中许多时,左连接可能有点棘手。 您可能必须巧妙地在连接周围使用括号,以使连接顺序正确。
这个 :
$sql = "select * from registration
left join programme on registration.id=programme.stuid
left join family on registration.id=family.stuid
left join address on registration.id=address.stuid
left join education on registration.id=education.stuid
left join extradetail on registration.id=extradetail.stuid
left join workexperience on registration.id=workexperience.stuid
left join demanddraft on registration.id=demanddraft.stuid
left join payonline on registration.id=payonline.stuid
where (DATE(registration.createddate)>='".$term1."'
AND DATE(registration.createddate)<='".$term2."')";
应该做的伎俩
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.