[英]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.