Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- MYSQL Syntax for NOT in where clause
August 8, 2005, 4:08 pm
rate this thread
I am confused with the syntax for NOT in MYSQL where clause and wonder
if an expert in MYSQL can enlighten me. There are possibly two places
NOT can go in:
select * from employee_data where NOT employee_id LIKE 'A%'
select * from employee_data where employee_id NOT LIKE 'A%'
In the first case, there was no data returned and no error message on
syntax either. But the second case returned the correct result. But I
am confused because if the first case is not right, the syntax error
should be thrown. Am I missing something?
Thank you in advance,
Re: MYSQL Syntax for NOT in where clause
On page http://dev.mysql.com/doc/mysql/en/string-comparison-functions.html:
expr NOT LIKE pat [ESCAPE 'escape-char']
This is the same as NOT (expr LIKE pat [ESCAPE 'escape-char']).
So the two forms you used are correct syntax, and according to the
above, _should_ yield the same results. I tried it on my test database,
and it seems to work as expected:
CREATE TABLE `t` (`c` varchar(10) default NULL);
INSERT INTO `t` VALUES ('A123'),('B123'),(NULL);
select * from `t` where `c` like 'A%';
select * from `t` where NOT `c` like 'A%';
Can you give a example of the data in the table, and the return sets
that are not equal?
- » looking for recommendation for database design book
- — Previous thread in » MySQL Database Forum
- » Americanas.com SALDO de TVs Com at 80% de Desconto (29798)
- — Newest thread in » MySQL Database Forum