【发布时间】:2012-06-25 07:45:46
【问题描述】:
类似的问题:
select from two tables where linked column can be null
column1tab1 column2tab1 order_number product amount
xx yy 123 p1 2
xx yy 456 p3 4
xx yy NULL NULL NULL
xx yy 789 p2 1
etc...
海报的输出如上。但是,当我添加 WHERE product = 'p1' 或 WHERE product = NULL 时,两者都返回一个空集。最后,我想拥有
SELECT *
FROM `t1`
LEFT OUTER JOIN `t2`
ON (`t1`.`id` = `t2`.`id2`)
WHERE `t2`.`product` = NULL
AND `t2`.`product` <> 'p1'
我做错了哪一部分?加入还是在哪里?还是别的什么?
【问题讨论】:
-
product = NULL将是product IS NULL,但除此之外,空值会自动使第二个product <> 'p1'为真。
标签: mysql left-join outer-join