문제

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