MySQL Query - The `where (varchar)` clause returns elements starting with a number. What for?

I have an interesting result and do not understand why.

SELECT * 
  FROM items im
 WHERE ItemNumber

ItemNumberis varchar(50).

The results of this query return all elements that ItemNumberbegin with a number. If it ItemNumberstarts with a letter, it is excluded.

Does anyone have an explanation why the request interacts in this way?

+5
source share
5 answers

MYSQL will return all rows with ItemNumber with number greater than equal to 0.5 and less than equal to -0.5. He considers the whole number greater >= +/-0.5 as true. A sentence whereonly works with true or false.

true >= -0.5  > false < 0.5 <= true

, mysql , >= +/-0.5 1 (true). true .

SELECT * FROM items im WHERE 1; // will return all rows.
SELECT * FROM items im WHERE 0.5; // will return all rows.
SELECT * FROM items im WHERE 0.4; // will return nothing.
SELECT * FROM items im WHERE 1 and 0.2; // will return nothing.
SELECT * FROM items im WHERE 0.3 or 0.5; // will return all rows.
+1

MySQL, , , ( , ).

, , . , , () , , thefor - "false". , , () '0', .

, , :

DELETE FROM foobar
WHERE 42;

. ANSI MySQL .

+6

WHERE BOOLEAN, , mysql varchar, , mysql , true.

SELECT * 
  FROM items im
  WHERE ItemNumber IS TRUE
0

MySQL , . / . . , , :

WHERE col 

,

0

, ItemNumber -.

WHERE ItemNumber NOT NULL

-

WHERE ItemNumber != ''
-1

All Articles