Difference between revisions of "Space Race/MATCH Tutorial"
ChrisHouston (talk | contribs) |
ChrisHouston (talk | contribs) |
||
Line 30: | Line 30: | ||
<div class="q nonum" data-lang="neo4j"> | <div class="q nonum" data-lang="neo4j"> | ||
<p><code>ORDER BY</code> works similarly to SQL, defaulting to ordering from low to high value. Adding <code>DESC</code> instead orders the result in descending order</p> | <p><code>ORDER BY</code> works similarly to SQL, defaulting to ordering from low to high value. Adding <code>DESC</code> instead orders the result in descending order</p> | ||
− | <p class='strong'>Return the names of the Astronauts ordered by their date of birth from | + | <p class='strong'>Return the names of the Astronauts ordered by their date of birth, from oldest to youngest.</p> |
<pre class="def"><nowiki>MATCH(n:Astronaut) RETURN n.first_name, n.surname ORDER BY n.surname;</nowiki> | <pre class="def"><nowiki>MATCH(n:Astronaut) RETURN n.first_name, n.surname ORDER BY n.surname;</nowiki> | ||
</pre> | </pre> | ||
Line 47: | Line 47: | ||
</pre> | </pre> | ||
</div> | </div> | ||
+ | |||
+ | ==Failure Rate== | ||
+ | <div> | ||
{{Acknowledgements}} | {{Acknowledgements}} |
Revision as of 12:04, 1 December 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;
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. Adding DESC
instead orders the result in descending order
Return the names of the Astronauts ordered by their date of birth, from oldest to youngest.
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;
Nicknames
In Neo4j, rather than empty properties being assigned a value of NULL
like in SQL, properties which are not assigned a value do not exist at all
This can be checked using the EXISTS()
function
Return the nicknames of the Astronauts who have them in reverse alphabetical order
MATCH(n:Astronaut)WHERE EXISTS(n.middle_names) RETURN n.middle_names;
MATCH(n:Astronaut)WHERE EXISTS(n.nickname) RETURN n.nickname ORDER BY n.nickname DESC;
Failure Rate
Acknowledgements
NoSQLZoo is made possible by the following open-source technologies: