Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
on 05-26-2022 06:43 AM
Hi
I'm working on a query that basically groups results in two different lists that are joined before being returned.
I'm having trouble finding the way to avoid adding elements from the list #2 if there's an element in list #1 with the same specific property (a code).
Example:
List #1: [ { code:"AA", name: "Anna" }, { code:"BB", name: "Bob" } ]
List #2: [ { code:"AA", name: null }, { code:"CC", name: "Charles" } ]
Desired output:
List: [ { code:"AA", name: "Anna" }, { code:"BB", name: "Bob" }, { code:"CC", name: "Charles" } ]
Any help is appreciated
Thanks.
Hi @mrksph !
You can try something like;
WITH [{ code:"AA", name: "Anna" }, { code:"BB", name: "Bob" } ] as l1, [ { code:"AA", name: null }, { code:"CC", name: "Charles" } ] as l2
return reduce(acc = l1, entry in [var5 in l2 where none(var3 in l1 where var3.code = var5.code)] | acc + entry)
Bennu