Search code examples
memgraphdb

Using DISTINC within aggregate functions in Memgraph?


Is there a way for me to simplify the following code: WITH DISTINCT n.prop as distinct_prop RETURN COUNT(distinct_prop)

As you can see, I use an aggregation function with distinct values. Can I somehow "skip" the WITH clause? It seems kind of redundant, but without it the code doesn't work.


Solution

  • With aggregation functions, you can use DISTINCT, so RETURN COUNT(DISTINCT n.prop) Check the docs here -> https://memgraph.com/docs/cypher-manual/clauses/return#10-returning-unique-results