A simple social network of people knowing each other.
LOAD CSV FROM "https://gist.githubusercontent.com/jexp/cdaca7e32d8fca630016/raw/people.csv" as row
MERGE (p1:Person {name: row[0]})
MERGE (p2:Person {name: row[1]})
MERGE (p1)-[:KNOWS]-(p2);
MATCH (person:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf)
WHERE person.name = "Joe"
AND NOT (person)-[:KNOWS]-(foaf)
RETURN DISTINCT foaf
Find all of Joe’s second-degree friends.
MATCH (user:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf)
WHERE user.name = "Joe" AND NOT(user)-[:KNOWS]-(foaf)
RETURN foaf
Find all friends that Joe has in common with Sally.
MATCH (user:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf:Person)
WHERE user.name = "Joe" AND foaf.name = "Sally"
RETURN friend