Cookies help us deliver our services. By using our services, you agree to our use of cookies. More information

Space Race/Relationships Tutorial

From NoSQLZoo
< Space Race
Revision as of 09:01, 29 November 2019 by ChrisHouston (talk | contribs) (Created page with "<p>Relationships are the most powerful part of graph-based databases. While some of the functionality these provide is possible under SQL using join tables for many to many re...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Relationships are the most powerful part of graph-based databases. While some of the functionality these provide is possible under SQL using join tables for many to many relationships, certain queries can be constructed which would require many joins in SQL.

All relationships in Neo4j are directional, that is they have a start and end node. As well as being also able to possess labels, they can also possess properties similar to nodes

Visualisation

Click here for 3d graph visualisation

Born in Russia

The item in [] represents a relationship between nodes, in this case the relationship possessing the label "BORN_IN"

Note the (startNode)-[:LABEL_NAME]->(endNode) format. The direction the arrow points shows which node is the end point.

It is perfectly valid to express this relationship as (endNode)<-[:LABEL_NAME]-(startNode)

If you are not concerned about the direction of the relationships, you can also MATCH based on (node1)-[:LABEL_NAME]-(node2)

Show the Surnames of Astronauts born in Russia, and the full name of Russia rather than the USA. Hint: Use the ISO 3166-1 Alpha-2 code in all caps

MATCH(n:Astronaut)-[:BORN_IN]->(c:Country) WHERE c.abbrev ='USA' RETURN n.surname, c.name;
MATCH(n:Astronaut)-[:BORN_IN]->(c:Country) WHERE c.abbrev= 'RU' RETURN n.surname, c.name;


Acknowledgements

NoSQLZoo is made possible by the following open-source technologies:

jQuery JSHint CodeMirror MediaWiki MariaDB