我的查询从某个区域(表 = 通知)中选择所有事件,但它确保这些事件没有被用户收藏(表 = 收藏夹)。
我的查询不起作用,我不确定为什么(它目前仍然显示用户收藏的事件)。
我的代码:
public function showCampusKT($uid)
{
$db = new db();
$sql = "SELECT * FROM notifications
WHERE
n_beacon = 'Creativity Gym'
OR
n_beacon = 'STIP'
OR
n_beacon = 'Cafetaria KruidTuin'
AND
n_id !=
(
SELECT n_id
FROM favorites
WHERE u_id ='".$uid."'
)";
$result = $db->conn->query($sql);
return $result;
}
最佳答案
你应该使用in
/not in
:
$sql = "select *
from notifications
where n_beacon in ('Creativity Gym','STIP','Cafetaria KruidTuin') and
n_id not in ( select n_id
from favorites
where u_id = '".$uid."')";
关于php - 查询多个 WHERE 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30897178/