george abousaydeh
george abousaydeh

Reputation: 15

MySQL: How to use OR between 2 different values in WHERE clause

I have a table in database with the name module, and I want the SELECT statement to show all values that has delete_time with either NULL or 0000-00-00 00:00:00. I used the following statement, but it did not work. The statement is:

$statment="SELECT * FROM module where delete_time IS NULL OR delete_time IS '0000-00-00 00:00:00 '";

Upvotes: 1

Views: 29

Answers (1)

Ray
Ray

Reputation: 41508

Two things:

  • You've got an extra space at the end of your quoted date time string '0000-00-00 00:00:00 '
  • Don't use IS to compare delete_time to '0000-00-00 00:00:00'. IS is to compare against boolean values or NULL. Use = instead.

Try this:

     $statment="SELECT * FROM module where delete_time IS NULL OR delete_time = '0000-00-00 00:00:00'";

Upvotes: 1

Related Questions