Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql: LIKE + NOT LIKE < ALL

Tags:

mysql

Can't understand such results:

SELECT COUNT(*) count FROM `persons_tmp` WHERE `p`.`medical_result1` NOT LIKE '%СО%6%'

Result: 36191

SELECT COUNT(*) count FROM `persons_tmp` WHERE `p`.`medical_result1` LIKE '%СО%6%'

Result: 140

SELECT COUNT(*) count FROM `persons_tmp`

Result: 42360

36191 + 140 < 42360. What's wrong?

like image 536
Serhii Koval Avatar asked Dec 28 '25 19:12

Serhii Koval


1 Answers

It's not counting null values because null essentially means "unknown". If it doesn't know the value, it can't do a comparison so it simply ignores those rows.

Try this to see if it makes up the difference:

SELECT COUNT(*) count FROM `persons_tmp` WHERE `p`.`medical_result1` IS NULL
like image 165
Joe Phillips Avatar answered Dec 30 '25 16:12

Joe Phillips



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!