MySQL - 选择用户不拥有的所有行

mic*_*eln 0 php mysql sql join

我有一个小的MySQL问题.我想选择我的表中包含用户不拥有的数据的所有行(它是一个交换工具).

例:

id  |  owner  |  event
----------------------
1   |    4    |    3
2   |    5    |    3
3   |    3    |    2
4   |    5    |    6
Run Code Online (Sandbox Code Playgroud)

我是老板#4.我希望看到除了我已经拥有的所有事件之外的所有事件,所以我希望得到如下结果:

event |  offered by
-------------------
2     |     3
6     |     5
Run Code Online (Sandbox Code Playgroud)

可以通过SQL选择此项,还是必须选择所有用户自己的事件并id从结果中删除所有其他事件?

Joh*_*Woo 7

SELECT  a.event, a.owner AS `Offered By`
FROM    tableName a
WHERE   a.event NOT IN
        (
            SELECT  b.event
            FROM    TableName b
            WHERE   owner = 4
        )
Run Code Online (Sandbox Code Playgroud)

或者使用JOIN我更喜欢的,

SELECT  a.event, a.owner AS `Offered By`
FROM    tableName a
        LEFT JOIN tableName b
            ON  a.event = b.event AND
                b.owner = 4
WHERE   b.event IS NULL
Run Code Online (Sandbox Code Playgroud)

OUTPUT

??????????????????????
? EVENT ? OFFERED BY ?
??????????????????????
?     2 ?          3 ?
?     6 ?          5 ?
??????????????????????
Run Code Online (Sandbox Code Playgroud)