我有这个问题:
SELECT `ca`.*, `a`.* FROM `container_asset` AS `ca` LEFT JOIN `asset` AS `a` ON ca.asset_id = a.id WHERE `container_id` = '4' AND `deleted` = '0' AND `reason` IN ('main', 'previous_version') ORDER BY `reason` ASC, `asset_id` DESC
我希望返回两行,但是当我用这个命令执行查询时:
$conn =new \mysqli('localhost', 'root', '12345', 'assetdb') or die("Error " . mysqli_error($link));
$res3 = $conn->query("SELECT `ca`.*, `a`.* FROM `container_asset` AS `ca` LEFT JOIN `asset` AS `a` ON ca.asset_id = a.id WHERE `container_id` = '4' AND `deleted` = '0' AND `reason` IN ('main', 'previous_version') ORDER BY `reason` ASC, `asset_id` DESC");
while ($r = mysqli_fetch_array($res3))
{
echo $r['id']."\n";
}
在获取结果时返回1行 但是当我直接执行查询时(在heidisql或phpmyadmin中),它会返回预期的结果,即2行。
我无法解释这个问题?
修改
我做了一些测试,如果我期待5行它返回4,所以它返回1行。
EDIT2
数据: container_asset表,asset_id foreing key in asset-> id:
"container_id" "asset_id" "reason" "1" "2" "main" "2" "1" "main" "3" "3" "main" "4" "3" "previous_version" "4" "4" "main"
资产表
"id" "asset_class" "deleted" "file_name" "1" "video" "0" "ÄÖ.jpg" "2" "image" "0" "èungrandeguitar.jpg" "3" "image" "0" "3.jpg" "4" "image" "0" "çàù.jpg"
编辑3
即使我删除了联接,结果仍然是错误的:
SELECT `ca`.* FROM `container_asset` AS `ca` WHERE ca.`container_id` = '4' AND `reason` IN ('main', 'previous_version') ORDER BY `reason` ASC, `asset_id` DESC