我有一个查询来查找名为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 =
插入的第一个查询的结果?
答案 0 :(得分:3)
您可以尝试使用IN
"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"].")"