0

I have a table called parents. It has a column named share_src which is indexed. Currently it is having 5 rows. Three of them have NULL while others have post_4556 as their value.

I am running this statement -: SELECT * FROM parents WHERE share_src != 'post_4556'. It should return those three rows which have share_src as NULL. But it is returning 0 rows.

What is wrong in my query. Thanks for help.

2 Answers 2

2

You need to specify the IS NULL condition to fetch the rows where that particular field may be NULL.

SELECT * 
FROM parents 
WHERE share_src != 'post_4556'
    OR share_src IS NULL;
Sign up to request clarification or add additional context in comments.

Comments

1

Nothing wrong with your query, this is how NULL values behaves.

Add OR share_src IS NULL to the WHERE clause, in order to return those that has nullable share_src too:

SELECT * 
FROM parents 
WHERE share_src != 'post_4556'
   OR share_src IS NULL;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.