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

Difference between revisions of "Space Race/MATCH Tutorial"

From NoSQLZoo
Jump to: navigation, search
Line 9: Line 9:
 
==Institutions==
 
==Institutions==
 
<div class="q nonum" data-lang="neo4j">
 
<div class="q nonum" data-lang="neo4j">
   <p>Use <code>MATCH</code> and <code>RETURN</code> to show nodes that are Institutions rather than Astronauts</p>
+
   <p>Use <code>MATCH</code> and <code>RETURN</code> to return nodes. Use <code>:</code> to specify what label(s) you wish the returned nodes to have. Not specifying any label will return ALL nodes</p>
 
   <p class='strong'>Show Institutions instead of Astronauts<p>
 
   <p class='strong'>Show Institutions instead of Astronauts<p>
 
   <pre class="def"><nowiki>MATCH(n:Astronaut) RETURN n;</nowiki>
 
   <pre class="def"><nowiki>MATCH(n:Astronaut) RETURN n;</nowiki>
Line 20: Line 20:
 
<div class="q nonum" data-lang="neo4j">
 
<div class="q nonum" data-lang="neo4j">
 
   <p>Use <code>WHERE</code> to specify conditions and the <code>.</code> operator to access individual properties of a node.</p>
 
   <p>Use <code>WHERE</code> to specify conditions and the <code>.</code> operator to access individual properties of a node.</p>
   <p class='strong'>Show the Surnames of Astronauts born in Russia rather than the USA <p>
+
   <p class='strong'>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<p>
   <pre class="def"><nowiki>MATCH(n:Astronaut)-[:BORN_IN]-(c:Country) WHERE c.abbrev ='usa' RETURN n.surname, c.name;</nowiki>
+
   <pre class="def"><nowiki>MATCH(n:Astronaut)-[:BORN_IN]-(c:Country{}) WHERE c.abbrev ='USA' RETURN n.surname, c.name;</nowiki>
 
</pre>
 
</pre>
<pre class="ans"><nowiki>MATCH(n:Astronaut)-[:BORN_IN]-(c:Country) WHERE c.abbrev= 'ru' RETURN n.surname;</nowiki>
+
<pre class="ans"><nowiki>MATCH(n:Astronaut)-[:BORN_IN]-(c:Country) WHERE c.abbrev= 'RU' RETURN n.surname, c.name;</nowiki>
 
</pre>
 
</pre>
 
</div>
 
</div>
  
 
{{Acknowledgements}}
 
{{Acknowledgements}}

Revision as of 09:20, 27 November 2019

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.

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