Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-06-2019 02:27 PM
I want to get all the distinct values of a particular node property, and map each one to a unique integer.
MATCH (n) RETURN DISTINCT n.property
But how do I continue to use the RETURN
ed list in the query?
Solved! Go to Solution.
11-06-2019 07:12 PM
The thing you're looking for is the WITH clause, which is like a RETURN but lets you continue operating on the results. This is where you would use aggregations, DISTINCT, additional filtering, and other stuff, and it also defines which variables remain in scope for later in the query: any variables you do not include in the WITH clause are dropped out of scope.
11-06-2019 07:12 PM
The thing you're looking for is the WITH clause, which is like a RETURN but lets you continue operating on the results. This is where you would use aggregations, DISTINCT, additional filtering, and other stuff, and it also defines which variables remain in scope for later in the query: any variables you do not include in the WITH clause are dropped out of scope.
11-08-2019 11:58 AM
Edit: I got it, thanks:
MATCH (n)
WITH DISTINCT n.property AS properties
...
I played with WITH
a little bit but could not get to work with DISTINCT
. Can you provide an example of using both those keywords?
11-08-2019 12:55 PM
The snippet you provided looks correct, what errors and/or unexpected behavior are you encountering? There may be a misassumption about what you think this is doing, so adding your understanding about what this is doing may help us figure that out.
Also if possible you may want to have a label present in the MATCH pattern, otherwise it will be looking to get distinct values for the property
property for all nodes in your graph.
All the sessions of the conference are now available online