我在Oracle中使用过NOT EXIST,但是我的带有NOT EXIST的SQL查询不适用于PHP / Mysqli
mysqli_query($link,"SELECT * FROM users u where u.active=1 AND u.allowed=1 NOT EXIST
(SELECT f.uid FROM featured2 f WHERE f.uid=u.id) ORDER BY RAND() ");
实际上,我希望表用户的所有结果除了 featured2 的结果,其中 f.uid = u.id
答案 0 :(得分:2)
MySQL中的NOT EXISTS
,你需要AND
。
SELECT *
FROM users u
WHERE u.active=1
AND u.allowed=1
AND NOT EXISTS(
SELECT f.uid FROM featured2 f WHERE f.uid=u.id
)
ORDER BY RAND()