To NOT or not?

  • When it is not good to use the NOT LIKE statement.

Query below is fine if you wanted to get all records with the given string.
SELECT * FROM `member`
WHERE suggestion LIKE  "Still to%"
Result of above query is 15 out of 44. But when negated as shown below, it will give an inconsistent result of 12 out of 44 which is lesser than expected(29 out of 44). MySQL seem to not implement this well(NULL values are left out).
SELECT * FROM `member`
WHERE suggestion NOT LIKE  "Still to%"
To correct the above query write the one as illustrated below instead. This will give us a result of 29 out of 44.
SELECT * FROM `member`
WHERE suggestion NOT LIKE  "Still to%"
OR suggestion IS NULL

- _

Add Comment

Sorry you must log in first to be able to add a comment. Click here to log in.
*/ ?>