Neo4j 简明教程
Neo4j - Optional Match Clause
OPTIONAL MATCH 子句用于搜索其中描述的模式,同时对模式的缺失部分使用 null。
The OPTIONAL MATCH clause is used to search for the pattern described in it, while using nulls for missing parts of the pattern.
OPTIONAL MATCH 与 match 子句相似,唯一的区别是它返回 null 作为模式缺失部分的结果。
OPTIONAL MATCH is similar to the match clause, the only difference being it returns null as a result of the missing parts of the pattern.
Syntax
以下是 OPTIONAL MATCH 与关系的语法。
Following is the syntax of the OPTIONAL MATCH with relationship.
MATCH (node:label {properties. . . . . . . . . . . . . .})
OPTIONAL MATCH (node)-->(x)
RETURN x
Example
以下就是一个尝试从节点 ICCT2013 中检索关系的 Cypher 查询示例。由于没有这样的节点,所以它返回 null。
Following is a sample Cypher Query which tries to retrieve the relations from the node ICCT2013. Since there are no such nodes, it returns null.
MATCH (a:Tornament {name: "ICC Champions Trophy 2013"})
OPTIONAL MATCH (a)-->(x)
RETURN x
执行上述查询,执行以下步骤:
To execute the above query, carry out the following steps −
Step 1 - 打开 Neo4j Desktop App 并启动 Neo4j Server。使用 URL http://localhost:7474/ 打开 Neo4j 的内置浏览器应用,如下面的屏幕截图所示。
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in the following screenshot.

Step 2 - 在美元提示符中复制并粘贴所需的查询,并按播放按钮(执行查询)突出显示在下面的屏幕截图中。
Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.
