cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Neo.ClientError.Statement.SyntaxError –– expected 'i/I' –– Query

Reuben
Graph Buddy

Hi,

Please, I am getting an error with a query, an example illustrated below. My objective is to obtain the family_names based on the matches of first_name etc. Where the most suitable match comes on top, and then other matches with common first_name follow in ascending order, as displayed in the table.

However, I am getting a Cypher syntax error. Please, how do you suggest I fix the issue?

Thanks.

example.jpg

MATCH(n:name{first_name:'Jay'})
MATCH(h:hometown{hometown:'New Jersey'})
MATCH(r:race {race:'Black'})
MATCH(f:family_name)
WHERE (f)-[:first_name]->(n)
AND (f)-[:hometown]->(h)
AND (f)-[:race]->(r)
WHERE f.first_name contains 'Jay'
RETURN f
ORDER BY f asc
LIMIT 10;
#Cypher #CSV #Neo4J #SyntaxError
1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

You have two ‘where’ clauses. Change the second ‘where’ clause to ‘and’.

Also, you can’t order by a node, as you are trying to do with ‘order by f’ change it to ‘order by f.first_name asc’

finally, you can’t have a pattern as a predicate. You can change them to use ‘exists’ to convert them to predicates. For example, change ‘(f)-[:first_name]->(n)’ in the ‘where’ clause to ‘exists((f)-[:first_name]->(n))’.

question: why do you need to match to the other nodes ‘race’ and ‘hometown’, as it seems you just want to find the last name of everyone whose first name contains ‘jay’. You will not receive your expected results you list with your query, because all three don’t match the values of race and hometown in your query. You should get your expected results with the following query:

MATCH(f:name)
WHERE f.first_name contains 'Jay'
RETURN f
ORDER BY f asc
LIMIT 10
Just realized one more issue, you limit the ‘name’ node to have a first name exactly equal to ‘Jay’ in the match, so the where clause looking for first names contains ‘Jay’ will not work.

View solution in original post

2 REPLIES 2

glilienfield
Ninja
Ninja

You have two ‘where’ clauses. Change the second ‘where’ clause to ‘and’.

Also, you can’t order by a node, as you are trying to do with ‘order by f’ change it to ‘order by f.first_name asc’

finally, you can’t have a pattern as a predicate. You can change them to use ‘exists’ to convert them to predicates. For example, change ‘(f)-[:first_name]->(n)’ in the ‘where’ clause to ‘exists((f)-[:first_name]->(n))’.

question: why do you need to match to the other nodes ‘race’ and ‘hometown’, as it seems you just want to find the last name of everyone whose first name contains ‘jay’. You will not receive your expected results you list with your query, because all three don’t match the values of race and hometown in your query. You should get your expected results with the following query:

MATCH(f:name)
WHERE f.first_name contains 'Jay'
RETURN f
ORDER BY f asc
LIMIT 10
Just realized one more issue, you limit the ‘name’ node to have a first name exactly equal to ‘Jay’ in the match, so the where clause looking for first names contains ‘Jay’ will not work.

Reuben
Graph Buddy

Got it!