From 21277019e2012f81c0b9a5bdfa29b3e7626aadad Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Fri, 16 Jun 2017 09:37:47 +0200 Subject: [PATCH] Elaborate on which variables are seen by ORDER BY Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D480 --- docs/user_technical/open-cypher.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/user_technical/open-cypher.md b/docs/user_technical/open-cypher.md index b7dcac18d..9620f6d15 100644 --- a/docs/user_technical/open-cypher.md +++ b/docs/user_technical/open-cypher.md @@ -153,6 +153,15 @@ Example. Ordering by first name descending and last name ascending. MATCH (n :Person) RETURN n ORDER BY n.name DESC, n.lastName +Note that `ORDER BY` sees only the variable names as carried over by `RETURN`. +This means that the following will result in an error. + + MATCH (n :Person) RETURN old AS new ORDER BY old.name + +Instead, the `new` variable must be used: + + MATCH (n: Person) RETURN old AS new ORDER BY new.name + The `ORDER BY` sub-clause may come in handy with `SKIP` and/or `LIMIT` sub-clauses. For example, to get the oldest person you can use the following.