Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "like" and "not like" in SQL MSAccess for the same field? [closed]

I would like to filter all the rows that are:

field like "*AA*" and field not like "*BB*"

But this is returning everything instead of showing all the rows that contains AA and doesn't contain BB.

well now it works like expected, just restarted ms access...

Sorry for my typo... :s updated

like image 962
Totty.js Avatar asked Dec 16 '22 01:12

Totty.js


2 Answers

Try this:

field like "*AA*" and field not like "*BB*"
like image 103
Paddy Avatar answered Jan 19 '23 00:01

Paddy


What I found out is that MS Access will reject --Not Like "BB*"-- if not enclosed in PARENTHESES, unlike --Like "BB*"-- which is ok without parentheses.

I tested these on MS Access 2010 and are all valid:

  1. Like "BB"

  2. (Like "BB")

  3. (Not Like "BB")

like image 43
Ponytell Avatar answered Jan 19 '23 01:01

Ponytell