Hello Team,
I need your help in understanding the concept of UNWIND and WITH.
I tried few examples of WITH and UNWIND but did not able to understand the concept and use of them.
Below are my examples:
QUERY 1
WITH [1,2,2,3,4,5,6,6] as X
RETURN DISTINCT(X) as Y
OUTPUT 1
Y
[1, 2, 2, 3, 4, 5, 6, 6]
OBSERVATION 1
Duplicates are available in output even though distinct is used.
QUERY 2
UNWIND [1,2,2,3,4,5,6,6] as X
RETURN DISTINCT (X) as Y
OUTPUT 2
Y
1
2
3
4
5
6
OBSERVATION 2
Duplicates are NOT available in output even though distinct is used.
QUERY 3:
UNWIND [1,2,2,3,4,5,6,6] as X
RETURN DISTINCT (X) as Y
WITH collect(Y)
OUTPUT 3:
Neo.ClientError.Statement.SyntaxError
Neo.ClientError.Statement.SyntaxError: RETURN can only be used at the end of the query (line 2, column 1 (offset: 32)) "RETURN DISTINCT (X) as Y" ^
Kindly help in telling when to use WITH and UNWIND.
Regards
AK