我的查询选择来自特定区域的所有事件(表格=通知)但是它确保用户没有收到这些事件(table = favorites)。
我的查询无效,我不确定原因(目前仍显示用户偏爱的事件)。
我的代码:
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;
}
答案 0 :(得分:1)
您应该使用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."')";