左连接查询错误

时间:2017-02-01 12:17:42

标签: mysql sql

我有两个表事件和enrolledevents当学生注册一个事件时,studentId和eventId存储在存储到enrolledevents表中 现在我希望得到所有未经学生注册的活动。

我的表格:  事件表enter image description here

EnrolledEvents enter image description here

任何人都可以给我查询我尝试了很多查询但是我没有得到结果

[...Array(7)].forEach((_, i) => fillWebsitePlaceFiller(i + 1))

1 个答案:

答案 0 :(得分:0)

将以下WHERE条件移至JOIN ON子句

    AND (enrolledevents.estudent_id NOT IN ('1')
    AND enrolledevents.eevent_id NOT IN ('3'))

SELECT 
    *
FROM
    events
        LEFT JOIN
    enrolledevents ON events.event_id = enrolledevents.eevent_id
                   AND enrolledevents.estudent_id <> '1'
                   AND enrolledevents.eevent_id <> '3'
WHERE
    events.event_occurance = 'daily'
        AND events.status = '1';