Benjoe
Benjoe

Reputation: 466

SQL didn't return a row with a column values of NULL

I just want to exclude the row if the status value is "hidden". But the rows with NULL values is being excluded also. The main objective is to hide only the status if it's hidden.

This is my query:

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

The output of the first query is:

enter image description here

This is my second query removing the "t.status != '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 ORDER BY t.created_date 
DESC

The output of the second query: enter image description here

I also tried something like t.status != "hidden" AND t.status IS NULL but still I'm not getting the rows with the status of NULL. Am I missing something?

Upvotes: 0

Views: 52

Answers (1)

Gauravsa
Gauravsa

Reputation: 6524

You can do this:

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

Upvotes: 3

Related Questions