horodav
horodav

Reputation: 13

MS Access: use of Not Like on multiple column is now working

I have a very simple table (as exemple)

table       period
nok         1
nok         2
nok         3
nok         2
ok          1
ok          2
ok          3

I need a query that showns all data but "nok" AND "1"

The result should be:

table       period
nok         2
nok         3
nok         2
ok          1
ok          2
ok          3

The query I wrote is the following:

SELECT Table1.table, Table1.period
FROM Table1
WHERE (((Table1.table)<>"nok") AND ((Table1.period)<>"1"));

but the result is:

table      period
ok         2
ok         3

I looks like the query applied a OR instead of a AND.

The query is so simple that this unexpected result makes me crazy ;)

Where is the mistake?

I also tried with

SELECT Table1.table, Table1.period
FROM Table1
WHERE ((Not (Table1.table)="nok") AND (Not (Table1.period)="1"));

or

SELECT Table1.table, Table1.period
FROM Table1
WHERE (((Table1.table) Not Like "nok") AND ((Table1.period) Not Like "1"));

with the same wrong result

Upvotes: 1

Views: 114

Answers (1)

forpas
forpas

Reputation: 164089

You want all the rows without "nok" AND "1", which can be written as:

WHERE NOT (Table1.table = "nok" AND Table1.period = "1")

and this is equivalent to:

WHERE (Table1.table <> "nok" OR Table1.period <> "1")

Upvotes: 1

Related Questions