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

2915 views mysql
4

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?

answered question

instead of 'AND', you need 'OR'. See my answer

Just my guessing.. Because your project don't have status.. Inner join will show base on id both of your table.. And don't see the null value in your t table.. If your project don't have status and it's null.. Of course it will show..

1 Answer

6

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

posted this

Have an answer?

JD

Please login first before posting an answer.