【问题标题】:mysql query : null values behavior when left joiningmysql查询:左加入时的空值行为
【发布时间】:2013-01-25 13:13:07
【问题描述】:

这个问题可能很简单,但我不明白空值在 mysql 语法中的行为方式。假设我有这个准备好的请求:

select t1.* 
from table1 t1 
left join table2 t2 
   on t1.id = t2.id 
   and some_entry = :value 
where t2.the_id is null

some_entry是table2的entry,t2.the_id是table2的增量索引。如果 table2 为空,输出会是什么?

【问题讨论】:

    标签: mysql sql select left-join


    【解决方案1】:
    What will be the output if table2 is empty?
    

    即使table2为空,它仍然会显示table1上的所有记录,因为你使用了LEFT JOIN

    【讨论】:

    • 即使 some_entry 是 table2 列?
    • 是的。试试这个and some_entry = :value where t2.the_id is NOT null 看看有什么不同。
    • btw,这个请求的原因是什么,因为如果table2不为空,t2.the_id就不会为空??
    • 并非始终如此。这些是t2.the_id 为空的时间:1.)the_id 没有任何值2.)t1.id = t2.id 但@ 的值987654329@。 3.)t1.id <> t2.id
    • 这是 select t1.* from table1 t1 join table2 t2 on t1.id = t2.id 和 some_entry = :value 的倒数
    猜你喜欢
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    相关资源
    最近更新 更多