在单个表中查询多个列条件

时间:2014-06-16 16:04:09

标签: sql

我的表包含多列数据,包含数据和空值的组合。在我选择的时候,我想只显示非空值的数据,我已经编写了如下所示的一个查询。

select Capability
     , BusinessStrategyMessaging
from tb_MBUPSheetData 
where (Capability is not null)
  and (BusinessStrategyMessaging is not null)

但它显示空表不显示表数据。我想在我选择时满足两列并显示数据。

请给我建议。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您希望根据您在选择中添加的列显示填充在表格中的注册表。所以你的查询没有错。问题是在你的表中没有注册表符合这两个条件:

    (Capability is not null)
and (BusinessStrategyMessaging is not null)

至少不是在同一时间。所以我认为你想要的是一个或另一个。要做到这一点,你必须把你的条件设为:

(    (Capability is not null)
OR (BusinessStrategyMessaging is not null) )

请注意,我添加了一些额外的括号,因为如果您有任何其他条件,它将不会影响它。