{"id":10314,"date":"2023-07-07T21:52:46","date_gmt":"2023-07-08T02:52:46","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=10314"},"modified":"2023-08-29T10:08:49","modified_gmt":"2023-08-29T15:08:49","slug":"neo4j-cypher-queries","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=10314","title":{"rendered":"NEO4J: More Cypher Queries"},"content":{"rendered":"<p>To get a count of returned records, Cypher uses <a href=\"https:\/\/neo4j.com\/docs\/cypher-manual\/current\/functions\/aggregating\/#functions-count\" target=\"_blank\" rel=\"noopener\">COUNT<\/a> pretty much the same way as SQL does<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-count.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10315\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-count.png\" alt=\"\" width=\"862\" height=\"214\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-count.png 862w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-count-300x74.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-count-768x191.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-count-750x186.png 750w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/a><\/p>\n<p>Interestingly, there are other aggregation functions that remind me of using the ELK API &#8212; I can get averages, min\/max, and standard deviation.<\/p>\n<p>&nbsp;<\/p>\n<p>Chaining MATCH statements functions similarly to a SQL JOIN &#8212; get the items with this label, add in some other stuff. And, just like an INNER JOIN, this means no data is returned when one of the conditions has no matches &#8212; Bill Clinton never lost an election, so we get a null data set here:<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatcha.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10317\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatcha.png\" alt=\"\" width=\"1434\" height=\"262\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatcha.png 1434w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatcha-300x55.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatcha-1024x187.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatcha-768x140.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatcha-750x137.png 750w\" sizes=\"auto, (max-width: 1434px) 100vw, 1434px\" \/><\/a><\/p>\n<p>The equivalent of an outer join is an <em>OPTIONAL<\/em> MATCH &#8212; here, the records from the first MATCH will be returned even if there is no corresponding record matching the second MATCH<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatch.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10316\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatch.png\" alt=\"\" width=\"1418\" height=\"368\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatch.png 1418w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatch-300x78.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatch-1024x266.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatch-768x199.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-optionalmatch-750x195.png 750w\" sizes=\"auto, (max-width: 1418px) 100vw, 1418px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/neo4j.com\/docs\/cypher-manual\/current\/clauses\/order-by\/\" target=\"_blank\" rel=\"noopener\">ORDER BY<\/a> also works in the same way it does in SQL. Multiple order parameters are separated by a comma and add DESC to do a DESCENDING ORDER<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-orderby.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10318\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-orderby.png\" alt=\"\" width=\"1270\" height=\"750\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-orderby.png 1270w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-orderby-300x177.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-orderby-1024x605.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-orderby-768x454.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-orderby-750x443.png 750w\" sizes=\"auto, (max-width: 1270px) 100vw, 1270px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/neo4j.com\/docs\/cypher-manual\/current\/clauses\/where\/\" target=\"_blank\" rel=\"noopener\">WHERE<\/a> can be used to create the equivalent of a LIKE query &#8212; the where =~ operator uses regular expression syntax, so you don&#8217;t just use % or * as a wildcard. Regex wildcards like .* (match any character zero or more times) are used.<\/p>\n<p><a href=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-substringsearch.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10319\" src=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-substringsearch.png\" alt=\"\" width=\"1398\" height=\"667\" srcset=\"https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-substringsearch.png 1398w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-substringsearch-300x143.png 300w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-substringsearch-1024x489.png 1024w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-substringsearch-768x366.png 768w, https:\/\/www.rushworth.us\/lisa\/wp-content\/uploads\/2023\/08\/cypher-query-substringsearch-750x358.png 750w\" sizes=\"auto, (max-width: 1398px) 100vw, 1398px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To get a count of returned records, Cypher uses COUNT pretty much the same way as SQL does Interestingly, there are other aggregation functions that remind me of using the ELK API &#8212; I can get averages, min\/max, and standard deviation. &nbsp; Chaining MATCH statements functions similarly to a SQL JOIN &#8212; get the items &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1896],"tags":[1902,1897],"class_list":["post-10314","post","type-post","status-publish","format-standard","hentry","category-neo4j","tag-cypher","tag-neo4j"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10314"}],"version-history":[{"count":3,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10314\/revisions"}],"predecessor-version":[{"id":10322,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10314\/revisions\/10322"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}