MySQL 显示存在于一个表中但不存在于另一个表中的行

use*_*793 3 mysql join

我有以下表格:

  1. organisation
    • organisation_id, organisation_name
  2. srp_reseller_buffer
    • organisation_id, property_id

我想写一个MySQL查询,显示我的组织中的所有记录,除了那些在srp_reseller_buffer,有一个property_idX的

这是我到目前为止:

SELECT * FROM organisation
    WHERE NOT EXISTS (
        SELECT * FROM organisation 
            LEFT OUTER JOIN srp_reseller_buffer 
                ON srp_reseller_buffer.organisation_id = organisation.organisation_id 
            WHERE srp_reseller_buffer.property_id is NULL 
Run Code Online (Sandbox Code Playgroud)

并且该 SQL 查询不起作用。它只是向我显示组织表中所有组织的列表。

Mar*_*c B 6

一个简单的左连接?

SELECT organisation.*
FROM organisation
LEFT JOIN srp_reseller_buffer ON
    (organisation.organisation_id = srp_reseller_buffer.organisation.id AND property_id = 'X')
WHERE srp_reseller_buffer.organisation_id IS NULL
Run Code Online (Sandbox Code Playgroud)

不存在于“右侧”(srp_reseller)的记录将为空。