我有这个查询:
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 行。
编辑2
数据:container_asset 表,asset_id 在asset->id 中的外键:
“container_id” “asset_id” “原因” “1”“2”“主要” “2”“1”“主要” “3” “3” “主要” "4" "3" "previous_version" “4”“4”“主要”
资产表
“id” “asset_class” “已删除” “file_name” "1" "视频" "0" "ÄÖ.jpg" "2" "图片" "0" "èungrandeguitar.jpg" “3”“图像”“0”“3.jpg” "4" "图片" "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