MySQL: fetching a null or an empty string
Posted
by Oden
on Stack Overflow
See other posts from Stack Overflow
or by Oden
Published on 2010-06-13T20:29:14Z
Indexed on
2010/06/13
20:32 UTC
Read the original article
Hit count: 241
mysql
|mysql-query
Hey,
I know whats the difference between a NULL
value and an empty string (""
) value, but if I want to get a value by using the OR
keyword, I get no result for a NULL
value
The table i want to query looks like this:
titles_and_tags
+----+----------+------+
| id | title | tag |
+----+----------+------+
| 1 | title1 | NULL |
| 2 | title2 | tag1 |
| 3 | title3 | tag2 |
+----+----------+------+
The query i use looks like this:
select * from `titles_and_tags` WHERE `title` LIKE "title" AND `tag` = "tag1" OR `tag` IS NULL
So i want to get here a rows (id: 1,2), BUT this results 0 rows. What have i done wrong?
© Stack Overflow or respective owner