gpt4 book ai didi

php - 查询多个 WHERE 不工作

转载 作者:行者123 更新时间:2023-11-28 23:58:10 26 4
gpt4 key购买 nike

我的查询从某个区域(表 = 通知)中选择所有事件,但它确保这些事件没有被用户收藏(表 = 收藏夹)。

我的查询不起作用,我不确定为什么(它目前仍然显示用户收藏的事件)。

我的代码:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com