Difference between revisions of "Space Race/MATCH Tutorial"
ChrisHouston (talk | contribs) |
ChrisHouston (talk | contribs) |
||
Line 27: | Line 27: | ||
</pre> | </pre> | ||
</div> | </div> | ||
+ | |||
==Neil Armstrong's Birthday== | ==Neil Armstrong's Birthday== | ||
<div class="q nonum" data-lang="neo4j"> | <div class="q nonum" data-lang="neo4j"> | ||
− | <p>When simply matching based on properties of a node, | + | <p>When simply matching based on properties of a node, use the <code>{}</code> with the format <code>{property:value}</code> |
<p class='strong'>Return Neil Armstrong's date of birth<p> | <p class='strong'>Return Neil Armstrong's date of birth<p> | ||
<pre class="def"><nowiki>MATCH(n:Astronaut{surname:"Gagarin",first_name:"Yuri"})RETURN n.dob;</nowiki> | <pre class="def"><nowiki>MATCH(n:Astronaut{surname:"Gagarin",first_name:"Yuri"})RETURN n.dob;</nowiki> | ||
</pre> | </pre> | ||
<pre class="ans"><nowiki>MATCH(n:Astronaut{surname:"Armstrong",first_name:"Neil"})RETURN n.dob;</nowiki> | <pre class="ans"><nowiki>MATCH(n:Astronaut{surname:"Armstrong",first_name:"Neil"})RETURN n.dob;</nowiki> | ||
+ | </pre> | ||
+ | </div> | ||
+ | |||
+ | |||
+ | ==The Young and Old== | ||
+ | <div class="q nonum" data-lang="neo4j"> | ||
+ | <p><code>ORDER BY</code> works similarly to SQL, defaulting to ordering from low to high value. | ||
+ | <p class='strong'>Return the names of the Astronauts ordered by their date of birth from earlier to later<p> | ||
+ | <pre class="def"><nowiki>MATCH(n:Astronaut) RETURN n.first_name, n.surname ORDER BY n.surname;</nowiki> | ||
+ | </pre> | ||
+ | <pre class="ans"><nowiki>MATCH(n:Astronaut) RETURN n.first_name, n.surname ORDER BY n.dob;</nowiki> | ||
</pre> | </pre> | ||
</div> | </div> |
Revision as of 09:19, 28 November 2019
Contents
Visualisation
Click here for 3d graph visualisation
Institutions
Use MATCH
and RETURN
to return nodes. Use :
to specify what label(s) you wish the returned nodes to have. Not specifying any label will return ALL nodes
Show Institutions instead of Astronauts
MATCH(n:Astronaut) RETURN n;
MATCH(n:Institution) RETURN n;
Born in Russia
Use WHERE
to specify conditions and the .
operator to access individual properties of a node.
The item in []
represents a relationship between nodes, in this case the relationship possessing the label "BORN_IN"
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;
Neil Armstrong's Birthday
When simply matching based on properties of a node, use the {}
with the format {property:value}
Return Neil Armstrong's date of birth
MATCH(n:Astronaut{surname:"Gagarin",first_name:"Yuri"})RETURN n.dob;
MATCH(n:Astronaut{surname:"Armstrong",first_name:"Neil"})RETURN n.dob;
The Young and Old
ORDER BY
works similarly to SQL, defaulting to ordering from low to high value.
Return the names of the Astronauts ordered by their date of birth from earlier to later
MATCH(n:Astronaut) RETURN n.first_name, n.surname ORDER BY n.surname;
MATCH(n:Astronaut) RETURN n.first_name, n.surname ORDER BY n.dob;
Acknowledgements
NoSQLZoo is made possible by the following open-source technologies: