Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Joing Four Tables in a single query

Author  Topic 

leosql
Starting Member

1 Post

Posted - 2015-03-19 : 18:27:34
Hi Friends,

I have four tables:
a, b, c and d

table a is related to table b by a foreign key. table b is related to c and so on.

I used the sql statement below to join the tables:

$result = mysql_query("SELECT a.colum1, a.column2,
b.column, c.column, d.column FROM a

JOIN b ON a.pkey = b.foreign key

JOIN c ON b.pkey = c.fkey
JOIN d ON c.pkey = d.fkey ")
or die(mysql_error());

while($row = mysql_fetch_array( $result )) {

echo $row['a.column1'].'<br>';
echo $row['a.column2'].'<br>';
echo $row['b.colum'].'<br>';
echo $row[‘c.coulm’].'<br>';
echo $row['d.column'].'<br>'; }
mysql_close()

?>

I succeeded in printing out the first record where the four tables are joined, but not other instances.my print out is this:
a.column1
a.colum2
b.colum
c.colum
d.colum

But there are about ten instances where the joing conditions are met. how do i print out all the records that have met the condition?

----

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-03-19 : 19:24:04
You'll want to post your question on a site that specializes in mysql. SQLTeam is for Microsoft SQL Server.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2015-03-20 : 02:48:49
It is more about showing data in the php application. You may need to visit php related forum

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -