2013-01-25 19 views
1

這個問題可能非常簡單,但我不明白空值是如何在mysql語法中表現的。假設我有這個準備要求:mysql查詢:null值加入時的行爲

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是表2項,t2.the_id是表2的增量索引。如果table2爲空,輸出是什麼?

回答

1
What will be the output if table2 is empty? 

即使table2是空的,它仍然會顯示在table1所有記錄,因爲你已經使用LEFT JOIN

+0

即使some_entry是table2列嗎? – user1611830

+0

是的。試試這個'和some_entry =:值 其中t2.the_id不爲空'來查看差異。 –

+0

順便說一句,這個請求的原因是什麼,因爲如果table2不是空的,t2.the_id不會是空的? – user1611830