[英]joining more than 5 tables in the same database using inner join
I have 6 tables in the same database. 我在同一数据库中有6个表。 I'd like to display all the data in these 6 tables and display it in the browser as a single table. 我想显示这6个表中的所有数据,并在浏览器中将其显示为一个表。 So I used full inner join for this purpose. 因此,我为此使用了完全内部联接。 I tried the code below, but its throwing an error like "mysql_num_rows() expects parameter 1 to be resource, boolean". 我尝试了下面的代码,但是它抛出诸如“ mysql_num_rows()期望参数1为资源,布尔值”的错误。
$sql ="SELECT * FROM table1 INNER JOIN table2 ON table1.pk1=table2.fk2
INNER JOIN table3 ON table1.pk1=table3.fk3 INNER JOIN
table4 ON table1.pk1=table4.fk4 INNER JOIN table5 ON
table1.pk1=table5.fk5 INNER JOIN table6 ON table1.pk = table6.fk6";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_array($result)) { //display function
}
And is it possible to use full outer join in mysql.? 并且可以在mysql中使用完全外部联接吗?
The result will be a boolean in case of the query failing. 如果查询失败,结果将为布尔值。 What is the output if you add the following: 如果添加以下内容,输出是什么:
if($result === false) {
var_dump(mysql_error());
}
Mysql doesn't support full joins however see https://stackoverflow.com/a/4796911/3691688 for workaround Mysql不支持完全连接,但是请参见https://stackoverflow.com/a/4796911/3691688了解解决方法
Also, you should format your queries for them to be easier to read(eg. seperate joins to their own lines and use indets) 另外,您应该为它们设置查询格式,以使其更易于阅读(例如,将单独的联接连接到它们自己的行并使用indets)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.