sql没有返回列值为null的行

nnvyjq4y  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(433)

我只想排除状态值为“hidden”的行。但是也排除了具有空值的行。主要目标是只隐藏隐藏的状态。
我的问题是:

SELECT t.id, t.task_name, t.status, t.assigned_user_task FROM 
`wp_hb_project_tasks` as t
INNER JOIN `wp_hb_projects` as p ON p.id = t.project_id
WHERE p.client_id = '2119' AND t.project_id = 101 AND t.status != "hidden" 
ORDER BY t.created_date DESC

第一个查询的输出是:

这是我删除“t.status!=”的第二个查询隐藏'':

SELECT t.id, t.task_name, t.status, t.assigned_user_task FROM 
`wp_hb_project_tasks` as t
INNER JOIN `wp_hb_projects` as p ON p.id = t.project_id
WHERE p.client_id = '2119' AND t.project_id = 101 ORDER BY t.created_date 
DESC

第二个查询的输出:

我也尝试过类似t.status的东西!=“hidden“并且t.status为null,但是我仍然没有得到状态为null的行。我错过什么了吗?

xzlaal3s

xzlaal3s1#

您可以这样做:

SELECT t.id, t.task_name, t.status, t.assigned_user_task FROM 
`wp_hb_project_tasks` as t
INNER JOIN `wp_hb_projects` as p ON p.id = t.project_id
WHERE p.client_id = '2119' AND t.project_id = 101 AND (t.status != "hidden" or t.Status is null)
ORDER BY t.created_date DESC

相关问题