Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Not Like Statement not working

I have the following code within a stored procedure.

WHERE     WPP.ACCEPTED = 1 AND     WPI.EMAIL LIKE '%@MATH.UCLA.EDU%' AND     (WPP.SPEAKER = 0 OR     WPP.SPEAKER IS NULL) AND     WPP.COMMENT NOT LIKE '%CORE%' AND     WPP.PROGRAMCODE = 'cmaws3' 

The NOT LIKE statement is not working, and yes before anyone says anything there are items with the COMMENT column that does not include CORE and all the other columns are ok.

Does anyone know what is wrong with this?

like image 964
mattgcon Avatar asked Oct 28 '09 16:10

mattgcon


People also ask

Does not like work in SQL?

The NOT LIKE operator in SQL is used on a column which is of type varchar . Usually, it is used with % which is used to represent any string value, including the null character \0 .

Is != And <> same in SQL?

If != and <> both are the same, which one should be used in SQL queries? Here is the answer – You can use either != or <> both in your queries as both technically same but I prefer to use <> as that is SQL-92 standard.

Can we use != In SQL query?

We can use both SQL Not Equal operators <> and != to do inequality test between two expressions. Both operators give the same output. The only difference is that '<>' is in line with the ISO standard while '!=


1 Answers

If WPP.COMMENT contains NULL, the condition will not match.

This query:

SELECT  1 WHERE   NULL NOT LIKE '%test%' 

will return nothing.

On a NULL column, both LIKE and NOT LIKE against any search string will return NULL.

Could you please post relevant values of a row which in your opinion should be returned but it isn't?

like image 82
Quassnoi Avatar answered Oct 03 '22 04:10

Quassnoi