cancel
Showing results for 
Search instead for 
Did you mean: 

What are the limitations in multiple WHERE conditions?

gigauser
Graph Buddy

I tried this query but failed with three conditions like this:

match (s:Stem)-[:STEM_OF]->(w:Word) where not w.vocab ends with 'XX' or not w.vocab ends with 'YY' or not w.vocab ends with 'ZZ'
return w.vocab, s.vocab limit 100

But it works with where not(w.vocab ends with 'XX' or w.vocab ends with 'YY' or w.vocab ends with 'ZZ')

1 ACCEPTED SOLUTION

Hi Gigauser,

I think what goes wrong here is that the two statements

NOT Statement A OR NOT Statement B OR NOT Statement C

and

NOT (Statement A OR Statement B OR Statement C)

are NOT (!) the same.

It is

NOT Statement A OR NOT Statement B OR NOT Statement C = NOT (Statement A AND Statement B AND Statement C)

on the one hand and on the other hand

NOT Statement A AND NOT Statement B AND NOT Statement C = NOT (Statement A OR Statement B OR Statement C).

But these two lines are not the same!

What probably happens is that you first query just gives you all words and not just the ones that you were looking for, right? This is because all words do not end in all (!) three of your endings. Your second query gives you what you want because there you look for all words that do not end in any (!) of the endings.

For further reference: this is called the De Morgan's laws ( De Morgan's laws - Wikipedia)

Regards,
Elena

View solution in original post

3 REPLIES 3

dana_canzano
Neo4j
Neo4j

I tried this query but failed with three conditions

how so?
you got wrong/unexpected results?
or you got an error?

Also what version of Neo4j is in use here?

Hi Gigauser,

I think what goes wrong here is that the two statements

NOT Statement A OR NOT Statement B OR NOT Statement C

and

NOT (Statement A OR Statement B OR Statement C)

are NOT (!) the same.

It is

NOT Statement A OR NOT Statement B OR NOT Statement C = NOT (Statement A AND Statement B AND Statement C)

on the one hand and on the other hand

NOT Statement A AND NOT Statement B AND NOT Statement C = NOT (Statement A OR Statement B OR Statement C).

But these two lines are not the same!

What probably happens is that you first query just gives you all words and not just the ones that you were looking for, right? This is because all words do not end in all (!) three of your endings. Your second query gives you what you want because there you look for all words that do not end in any (!) of the endings.

For further reference: this is called the De Morgan's laws ( De Morgan's laws - Wikipedia)

Regards,
Elena

Thank you for the tips!

God bless you and dana!

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.