Skip to content

Commit 943cf62

Browse files
committed
tags for ORDER BY, SKIP and UNWIND
1 parent f959423 commit 943cf62

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

modules/ROOT/pages/clauses/order-by.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ CREATE
4040
`ORDER BY` is used to sort the output.
4141

4242
.Query
43+
tag::clauses_order_by[]
4344
[source, cypher]
4445
----
4546
MATCH (n)
4647
RETURN n.name, n.age
4748
ORDER BY n.name
4849
----
50+
end::clauses_order_by[]
4951

5052
The nodes are returned, sorted by their name.
5153

@@ -67,12 +69,14 @@ You can order by multiple properties by stating each variable in the `ORDER BY`
6769
Cypher will sort the result by the first variable listed, and for equals values, go to the next property in the `ORDER BY` clause, and so on.
6870

6971
.Query
72+
tag::clauses_order_by_multiple[]
7073
[source, cypher]
7174
----
7275
MATCH (n)
7376
RETURN n.name, n.age
7477
ORDER BY n.age, n.name
7578
----
79+
end::clauses_order_by_multiple[]
7680

7781
This returns the nodes, sorted first by their age, and then by their name.
7882

@@ -246,12 +250,14 @@ Read more about this capability in xref::indexes/search-performance-indexes/usin
246250

247251

248252
.Standalone use of `ORDER BY`
253+
tag::clauses_order_by_standalone[]
249254
[source, cypher]
250255
----
251256
MATCH (n)
252257
ORDER BY n.name
253258
RETURN collect(n.name) AS names
254259
----
260+
end::clauses_order_by_standalone[]
255261

256262
.Result
257263
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -264,6 +270,7 @@ RETURN collect(n.name) AS names
264270
The following query orders all nodes by `name` descending, skips the first row and limits the results to one row.
265271

266272
.`ORDER BY` used in conjunction with `SKIP` and `LIMIT`
273+
tag::clauses_order_by_descending[]
267274
[source, cypher]
268275
----
269276
MATCH (n)
@@ -272,6 +279,7 @@ SKIP 1
272279
LIMIT 1
273280
RETURN n.name AS name
274281
----
282+
end::clauses_order_by_descending[]
275283

276284
.Result
277285
[role="queryresult",options="header,footer",cols="1*<m"]

modules/ROOT/pages/clauses/skip.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ The following query returns the middle two rows, with `SKIP` skipping the first
7070
7171
.Query
7272
[source, cypher]
73+
tag::clauses_skip[]
7374
----
7475
MATCH (n)
7576
RETURN n.name
7677
ORDER BY n.name
7778
SKIP 1
7879
LIMIT 2
7980
----
81+
end::clauses_skip[]
8082
8183
.Result
8284
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -126,12 +128,14 @@ d|Rows: 4
126128
`SKIP` can be used as a standalone clause, or in conjunction with xref:clauses/order-by.adoc[`ORDER BY`] or xref:clauses/limit.adoc[`LIMIT`].
127129

128130
.Standalone use of `SKIP`
131+
tag::clauses_skip_standalone[]
129132
[source, cypher]
130133
----
131134
MATCH (n)
132135
SKIP 2
133136
RETURN collect(n.name) AS names
134137
----
138+
end::clauses_skip_standalone[]
135139

136140
.Result
137141
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -169,6 +173,7 @@ RETURN collect(n.name) AS names
169173
`OFFSET` was introduced as part of Cypher's xref:appendix/gql-conformance/index.adoc[] and can be used as a synonym to `SKIP`.
170174

171175
.Query
176+
tag::clauses_skip_offset[]
172177
[source, cypher]
173178
----
174179
MATCH (n)
@@ -177,6 +182,7 @@ OFFSET 2
177182
LIMIT 2
178183
RETURN collect(n.name) AS names
179184
----
185+
end::clauses_skip_offset[]
180186

181187
.Result
182188
[role="queryresult",options="header,footer",cols="1*<m"]

modules/ROOT/pages/clauses/unwind.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ The `UNWIND` clause requires you to specify a new name for the inner values.
2929
We want to transform the literal list into rows named `x` and return them.
3030

3131
.Query
32+
tag::clauses_unwind_list[]
3233
[source, cypher]
3334
----
3435
UNWIND [1, 2, 3, null] AS x
3536
RETURN x, 'val' AS y
3637
----
38+
end::clauses_unwind_list[]
3739

3840
Each value of the original list -- including `null` -- is returned as an individual row.
3941

@@ -109,13 +111,15 @@ The two lists -- _a_ and _b_ -- are concatenated to form a new list, which is th
109111
Multiple `UNWIND` clauses can be chained to unwind nested list elements.
110112

111113
.Query
114+
tag::clauses_unwind_nested_list[]
112115
[source, cypher]
113116
----
114117
WITH [[1, 2], [3, 4], 5] AS nested
115118
UNWIND nested AS x
116119
UNWIND x AS y
117120
RETURN y
118121
----
122+
end::clauses_unwind_nested_list[]
119123

120124
The first `UNWIND` results in three rows for `x`, each of which contains an element of the original list (two of which are also lists); namely, `[1, 2]`, `[3, 4]`, and `5`.
121125
The second `UNWIND` then operates on each of these rows in turn, resulting in five rows for `y`.
@@ -212,13 +216,15 @@ Create a number of nodes and relationships from a parameter-list without using `
212216
----
213217

214218
.Query
219+
tag::clauses_unwind_create_nodes[]
215220
[source, cypher]
216221
----
217222
UNWIND $events AS event
218223
MERGE (y:Year {year: event.year})
219224
MERGE (y)<-[:IN]-(e:Event {id: event.id})
220225
RETURN e.id AS x ORDER BY x
221226
----
227+
end::clauses_unwind_create_nodes[]
222228

223229
Each value of the original list is unwound and passed through `MERGE` to find or create the nodes and relationships.
224230

0 commit comments

Comments
 (0)