我有大约 10 张桌子。一个具有主键的表和所有其他表通过外键连接到该单个表。例如。
Table main : 1,2,3,4,5,6,7,8
Tablechild: 1,2,3
Tableanchild: 1,3,5
Tableachild: 1,2,4,5
我想提取主表和所有其他表的完整数据,例如。
1 "tablechild data" "tableanchild data" tableachild data"
2 tablechild data tableachild data
3 tablechild data tableanchild data
4
5
6
7
8
我使用过left join
,但它提供了冗余数据。对于每个显示外键的表,请提前致谢。
$sql = "SELECT * FROM login AS jon
LEFT JOIN re as rec ON jon.no=rec.no
LEFT JOIN bio as bio ON jon.no=bio.no
LEFT JOIN pon as po ON jon.no=po.no
LEFT JOIN rec as re ON jon.no=re.no
LEFT JOIN spn as sp ON jon.no=sp.no" ;
我也试过
" SELECT login.no,re.name ,re.num,bio.address,bio.phone,pon.lline,pon.set,rec.book,rec.pen,spn.rub,spn.stylo FROM login,re,bio,pon,rec,spn WHERE login.no=re.no AND login.no=bio.no AND login.no=pon.no AND login.no=rec.no AND login.no=spn.no ";
我想做 SELECT Ax , By , Bz, Cd ,Cf FROM A,B,C WHERE AX is distinct as x is primary key in A and foreign key in others 。预期产出
1 B data
2 B data C data
3 C data
4 B data C data
5
现在我得到
1 B data
1 ....
1 .......
2 ....
2 ......
3
4
4
5