I’m wondering if there is any particular performance advantage in using LIKE over NOT LIKE or vice versa. For example:
say I have 1000 rows (yes not very many, but after all this is an example) and only 50 have the word world in its hello column after querying the db using
SELECT id FROM table WHERE hello LIKE'%world%'
or
SELECT id FROM table WHERE hello NOT LIKE '%world%'
LIKE returns 50 while using NOT LIKE returns 950
My question is not on which you should use in any particular scenario but rather if there is any performance cost for which you use as both will have to ‘search’ the entire table anyway
🙂
There is no performance difference.
NOTjust inverts the result of whatever follows it. The logical inversion is an extremely quick operation, taking just a few nanoseconds on a modern processor….All of the expense will be related to the number of rows selected, and tracking them for other parts of the query.