質問

I have a table linksbase that is filled with values. lastvisited is datetime and is NULL everywhere (nulls are allowed). I run query in phpmyadmin (same via Java) and go empty result:

SELECT `id` FROM `linksbase` WHERE `lastvisited` = NULL

What's more, if I run

SELECT `id` FROM `linksbase` WHERE `lastvisited` != NULL 

I also get emplty result. If I run

SELECT * FROM linksbase WHERE 1

I get a list of rows like should be (so, it's working).

What's wrong with the query and why two mutually excluding queries return 0 rows.

役に立ちましたか?

解決

You should use

SELECT `id` FROM `linksbase` WHERE `lastvisited` IS NULL

and

SELECT `id` FROM `linksbase` WHERE `lastvisited` IS NOT NULL

他のヒント

You should be using IS NULL or IS NOT NULL instead of comparing NULL with ! or != operators. Those will always be false.

if you have empty columns and not null , then consider to use this

 SELECT `id` FROM `linksbase` WHERE  `lastvisited` = ''  OR `lastvisited` IS NULL

this will look for empty columns and columns with null .

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top