查询WHERE响应为空输入null

时间:2016-12-15 14:23:49

标签: sql

我需要制定一个查询并坚持下去。需要有关WHERE x = x的帮助,但如果没有输入null或继续。

实施例

SELECT
    a.value1, a.value2,
    b.vlaue1, b.value2,
    c.value1
FROM
    columnX a,
    columnY b,
    columnZ c
WHERE
    a.value1 = b.value3
    and b.value2 = c.value4
    and c.value1 = a.value5
        or c.value1 is null

我需要c.value1的最后一个WHERE为其检查或者没有值输入空值。现在它似乎窒息并循环。

1 个答案:

答案 0 :(得分:3)

使用连接语法,左连接为C:

SELECT
    a.value1, a.value2,
    b.vlaue1, b.value2,
    c.value1
FROM columnX a
INNER JOIN columnY b
  on a.value1 = b.value3
LEFT JOIN columnZ c
  on b.value2 = c.value4
  and c.value1 = a.value5