I am trying to make a selection from a MySQL database using the syntax WHERE col LIKE \'%\'
but I want to select even NULL
values with that query. Is t
This statement returns all rows EXCEPT rows which have NULL in column1
SELECT * FROM table WHERE column1 LIKE '%'
To get all rows including rows with NULL in column1, use this:
SELECT * FROM table WHERE IFNULL(column1,1) LIKE '%'
from the MySQL documentation:
IFNULL(expr1,expr2)
If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. IFNULL() returns a numeric or string value, depending on the context in which it is used.
There's one caveat however: If you have an index on column1, it won't be used in this query, so things could get slow in larger tables...