Skip to content

Instantly share code, notes, and snippets.

@qmaruf
Last active August 29, 2015 14:00
Show Gist options
  • Save qmaruf/1e75e03957b9297c71b9 to your computer and use it in GitHub Desktop.
Save qmaruf/1e75e03957b9297c71b9 to your computer and use it in GitHub Desktop.
neo4j, create sample db
#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