Skip to content

Instantly share code, notes, and snippets.

@qmaruf
Created May 16, 2014 16:12
Show Gist options
  • Save qmaruf/c9509dea229de935466e to your computer and use it in GitHub Desktop.
Save qmaruf/c9509dea229de935466e to your computer and use it in GitHub Desktop.
#create db
create(a{n:"a"}),(b{n:"b"}),(c{n:"c"}),(d{n:"d"}),(e{n:"e"}),
a-[:parent_of]->b,
a-[:parent_of]->c,
b-[:parent_of]->d,
d-[:parent_of]->e,
e-[:parent_of]->c,
d-[:parent_of]->c;
#do query
match path=p<-[:parent_of*]-common_ancestor-[:parent_of*]->h
return common_ancestor as most_recent_common_ancestor
order by length(path)
limit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment