且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MYSQL-仅当LEFT JOIN中的行不存在时选择

更新时间:2023-01-31 14:01:42

左连接将为不匹配项生成 null 行。

这是需要过滤的 null 行。

The left join will produce null rows for the mismatches.
It's those null rows that you need to filter on.

SELECT * FROM mail  
LEFT JOIN block ON (block.blocker = 'Bob') 
WHERE block.blocker IS NULL

这是一种将固定值连接起来的扼杀,更常见加入(给您的表)将是:

It's kind of strangle to be joining on a fixed value however, a more common join (given your tables) would be:

SELECT * FROM mail  
LEFT JOIN block ON (block.blocker = mail.receiver
                and block.blocked = mail.sender)<<-- these should match
WHERE block.blocker IS NULL                     <<-- select only mismatches
AND mail.receiver like 'bob';