我有一个查询来查找名为entryEntryPairs的表中的关系:
if (!$result = $mysqli->query(
"SELECT entryIdA AS relatedId FROM entryEntryPairs WHERE entryIdB = ".$inRow["id"].
" UNION ".
"SELECT entryIdB AS relatedId FROM entryEntryPairs WHERE entryIdA = ".$inRow["id"]
)) return "Something went wrong";
但是,我真正想要的是将所有
relatedId
作为对名为entry的表的更大查询的一部分。某种形式的东西:SELECT title FROM entry WHERE id =
id =
右侧缺失的部分将是所有的relatedIds
。这可以在一个更大的查询中完成吗?还是我必须遍历插入每个relatedId
到id =
右侧的第一个查询的结果? 最佳答案
你可以试试
"SELECT title FROM entry WHERE id IN (SELECT entryIdA AS relatedId FROM entryEntryPairs WHERE entryIdB = ".$inRow["id"].
" UNION ".
"SELECT entryIdB AS relatedId FROM entryEntryPairs WHERE entryIdA = ".$inRow["id"].")"
关于php - 选择列等于其他查询中任何值的位置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26479162/