Prev |  | Next

## 15.9. Start

Every query describes a pattern, and in that pattern one can have multiple starting points. A starting point is a relationship or a node where a pattern is anchored. You can either introduce starting points by id, or by index lookups. Note that trying to use an index that doesn’t exist will throw an exception.

Figure 15.2. Graph

### 15.9.1. Node by id

Binding a node as a starting point is done with the `node(*)` function.

| Note
Neo4j reuses its internal ids when nodes and relationships are deleted, which means it’s bad practice to refer to them this way. Instead, use application generated ids.

Query.

    START n=node(1)
    RETURN n

The corresponding node is returned.

Result

n
1 row
1 ms
`Node[1]{name:"A"}`

### 15.9.2. Relationship by id

Binding a relationship as a starting point is done with the `relationship(*)` function, which can also be abbreviated `rel(*)`. See Section 15.9.1, “Node by id” for more information on Neo4j ids.

Query.

    START r=relationship(0)
    RETURN r

The relationship with id `0` is returned.

Result

r
1 row
0 ms
`:KNOWS[0] {}`

### 15.9.3. Multiple nodes by id

Multiple nodes are selected by listing them separated by commas.

Query.

    START n=node(1, 2, 3)
    RETURN n

This returns the nodes listed in the `START` statement.

Result

n
3 rows
0 ms
`Node[1]{name:"A"}`
`Node[2]{name:"B"}`
`Node[3]{name:"C"}`

### 15.9.4. All nodes

To get all the nodes, use an asterisk. This can be done with relationships as well.

Query.

    START n=node(*)
    RETURN n

This query returns all the nodes in the graph.

Result

n
3 rows
0 ms
`Node[1]{name:"A"}`
`Node[2]{name:"B"}`
`Node[3]{name:"C"}`

### 15.9.5. Node by index lookup

When the starting point can be found by using index lookups, it can be done like this: `node:index-name(key = "value")`. In this example, there exists a node index named `nodes`.

Query.

    START n=node:nodes(name = "A")
    RETURN n

The query returns the node indexed with the name "`A`".

Result

n
1 row
0 ms
`Node[1]{name:"A"}`

### 15.9.6. Relationship by index lookup

When the starting point can be found by using index lookups, it can be done like this: `relationship:index-name(key = "value")`.

Query.

    START r=relationship:rels(name = "Andrés")
    RETURN r

The relationship indexed with the `name` property set to "`Andrés`" is returned by the query.

Result

r
1 row
0 ms
`:KNOWS[0] {name:"Andrés"`

### 15.9.7. Node by index query

When the starting point can be found by more complex Lucene queries, this is the syntax to use: `node:index-name("query")`.This allows you to write more advanced index queries.

Query.

    START n=node:nodes("name:A")
    RETURN n

The node indexed with name "A" is returned by the query.

Result

n
1 row
0 ms
`Node[1]{name:"A"}`

### 15.9.8. Multiple starting points

Sometimes you want to bind multiple starting points. Just list them separated by commas.

Query.

    START a=node(1), b=node(2)
    RETURN a,b

Both the nodes `A` and the `B` are returned.

Result

a | b
--- | ---
1 row
0 ms
`Node[1]{name:"A"}` | `Node[2]{name:"B"}`

Copyright © 2013 Neo Technology

Prev | Up | Next
| Home |