4 ms·
How would you represent a self join?
by AlphaSite 5y ago
How would you represent a self join?
- RedCrowbar 5y agoIf given a recursive schema like this: type Tree { property value -> str link parent -> Tree } you'd traverse the link as usual: SELECT Tree { value, parent: { value } } FILTER .parent.parent.parent.value = 'foo' If there's a need to self-join on an arbitrary property, then you could use a `WITH` clause to explicitly bind the two sets: WITH T1 := Tree, T2 := Tree SELECT T1 { similarly_valued := (SELECT T2 FILTER T1.value = T2.value) }
- AlphaSite 5y agoThanks!
- singpolyma3 5y agoExample from the cheatsheet: ``` WITH P := Person SELECT Person { id, full_name, same_last_name := ( SELECT P { id, full_name, } FILTER # same last name P.last_name = Person.last_name AND # not the same person P != Person ), } FILTER EXISTS .same_last_name ```