Search code examples
mysqlsql-like

MySQL searching by LIKE and AND


I have such SQL query

SELECT * FROM fl_entities WHERE  name LIKE '%FTSE%' AND source != 'ABC';

and didn't get results. But when i used

 SELECT * FROM fl_entities WHERE  name LIKE '%FTSE%' AND source is NULL;

I got the result

+----+----------+-----------+--------+--------+
| id | name     | core_name | type   | source |
+----+----------+-----------+--------+--------+
| 31 | FTSE     | FTSE      | factor | NULL   |
+----+----------+-----------+--------+--------+

What is wrong with first query? Please help.


Solution

  • NULLS are not equal to anything so you can't compare them by = or != comparisons you have to use IS NULL or IS NOT NULL.