Bug #18602 Updated: Table left joins return wrong results
| From: | php_bugs at intrax dot com | Date: | Fri, 26 Jul 2002 18:56:33 +0000 |
| Subject: | Bug #18602 Updated: Table left joins return wrong results | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-15378@lists.php.net to get a copy of this message | ||
ID: 18602
Updated by: php_bugs@intrax.com
Reported By: php_bugs@intrax.com
-Status: Open
+Status: Bogus
Bug Type: MySQL related
Operating System: all (bug in RH7.2 & Tru64 4.0F)
PHP Version: 4.2.2
New Comment:
id 10 T error
Previous Comments:
------------------------------------------------------------------------
[2002-07-26 13:52:09] php_bugs@intrax.com
Linux:
MySQL v3.53.21
Server version: Apache/2.0.39
Tru64 Unix:
MySQL v3.21.3
Server version: Apache/1.3.6 and
Server version: Apache/2.0.39
PHP compile line:
configure --with-mysql=/usr/local \
--with-apxs2=/usr/local/apache2/bin/apxs
MySQL database schema:
Project table:
primary key (projname)
projname varchar(60)
si_guy varchar(30)
hw_guy varchar(30)
sw_guy varchar(30)
User table:
primary key (user)
user varchar(30)
fullname varchar(30)
With either version of MySQL, typing this query into MySQL's command
line interface works:
select p.projname, u1.fullname, u2.fullname,
u3.fullname from projects p
left join users u1 on u1.user = p.si_guy
left join users u2 on u2.user = p.sw_guy
left join users u3 on u3.user = p.hw_guy
However, this PHP query returns the project name, and the hw_guy only.
If I shuffle the left joins around, I find that PHP always returns the
last left join, and drops the two other left joins.
<?php
/* Connecting, selecting database */
$link = mysql_connect() or die("Can't connect to MySQL
database!");
mysql_select_db("proj2") or die("Could not select the project
database");
/* Performing SQL query */
$query = "select p.projname, u1.fullname,
u2.fullname, u3.fullname from projects p
left join users u1 on u1.user = p.si_guy
left join users u2 on u2.user = p.sw_guy
left join users u3 on u3.user = p.hw_guy";
$result = mysql_query($query) or die("Query failed");
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "<TR>\n";
foreach ($line as $col_value) {
print "\t\t<TD ALIGN=CENTER>$col_value</TD>\n";
}
print "</TR>\n";
}
mysql_free_result($result);
mysql_close($link);
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18602&edit=1