Note that there are some explanatory texts on larger screens.

plurals
  1. POjoining multiple sql tables on basis of primary key
    text
    copied!<p>I have around 10 tables. One table that has primary key and all other tables are connected to that single table through foreign key. eg.</p> <pre><code>Table main : 1,2,3,4,5,6,7,8 Tablechild: 1,2,3 Tableanchild: 1,3,5 Tableachild: 1,2,4,5 </code></pre> <p>I want to extract complete data for main table and all other tables eg.</p> <pre><code>1 "tablechild data" "tableanchild data" tableachild data" 2 tablechild data tableachild data 3 tablechild data tableanchild data 4 5 6 7 8 </code></pre> <p>I used <code>left join</code> but it is giving reduntant data. For every table displaying foreign key thank you in advance.</p> <pre><code>$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" ; </code></pre> <p>I also tried </p> <pre><code>" 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 "; </code></pre> <p>I want to do like SELECT A.x , B.y , B.z, C.d ,C.f FROM A,B,C WHERE A.X is distinct as x is primary key in A and foreign key in others . expected output</p> <pre><code>1 B data 2 B data C data 3 C data 4 B data C data 5 </code></pre> <p>now i am getting</p> <pre><code> 1 B data 1 .... 1 ....... 2 .... 2 ...... 3 4 4 5 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload