Languages

MySQL - select only rows where removal_time is NULL

3 points
Asked by:
Root-ssh
7497

How to select only rows where removal_time is NULL with MySQL?

Doesn't work:

SELECT * FROM qa_post_comments WHERE removal_time = NULL;

It can be executed, but it doens't return any values at all - NULL or NOT NULL.
How to make it work?

 

1 answers
1 points
Answered by:
Root-ssh
7497

Correct SQL:

SELECT * FROM qa_post_comments WHERE removal_time IS NULL

Where we want to select rows with only NULL values:

IS NULL

And if we want to select rows with NOT NULL values:

IS NOT NULL

Eg:

SELECT * FROM qa_post_comments WHERE removal_time IS NOT NULL

Is is very common mistake and a lot of people try to use:

  • = NULL
  • != NULL
0 comments Add comment
Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.