mysql left join and not equals should return only one row

mysql left join and not equals should return only one row

有人可以帮我查询以下要求吗?

上面两个table我在下面写了left join query

select distinct result 
from a 
    left join b on a.number = b.reference 
where a.color='red' and b.value != '10'

此查询return将 1 和 2 作为输出。

但我只期望 2 作为输出,因为 table b 中的 list1 具有 value:10,因此如果列表中的值匹配,则查询不应 return 行。

我知道您想要 a 中的“红色”行,而 bvalue 10 中没有匹配项。我认为用 not exists:

来表达更好
select a.*
from tablea a 
where a.color = 'red' not exists (
    select 1
    from tableb b
    where b.reference = a.number and b.value = 10
)
select distinct(result) from a where color='red' and
number not in (select reference from b where value =10)

select result 
from a 
    left join b on a.number = b.reference AND b.value = 10
where a.color='red' and b.reference IS NULL

可以left join做到这一点。但是过滤条件大多在on子句中:

select a.result 
from a left join
     b
     on a.number = b.reference and b.value = '10'
where a.color='red' and b.reference is null;