FROM PREVIOUS

Generic Description

FROM PREVIOUS imports the result rows from the immediately previous statement in a semicolon-delimited Cypher script. It must be the first clause of the statement that consumes those rows.

MATCH (u:User) RETURN u.uid AS uid, u.name AS name;

FROM PREVIOUS AS row
MATCH (o:Order {user_uid: row.uid})
RETURN row.name AS name, o.order_id AS order_id

Consumer-Level Explanation

Use FROM PREVIOUS AS row when the output of one statement should become the input table for the next statement. Each imported row is exposed as a map. The map keys are the column names returned by the previous statement.

If the previous statement returns uid and name, the next statement can read row.uid and row.name.

More Detailed Explanation

FROM PREVIOUS creates one input row per previous result row. The alias names that row map, not each individual column. This keeps the handoff explicit and avoids accidentally merging column scopes from separate statements.

The clause is script-local:

Advanced Example

MATCH (d:Document)
WHERE cosine_similarity(d.embedding, vector([0.22, 0.18, 0.44])) > 0.82
RETURN d.doc_id AS doc_id, d.title AS title;

FROM PREVIOUS AS hit
MATCH (d:Document {doc_id: hit.doc_id})-[:MENTIONS]->(p:Person)
RETURN
  hit.title AS document_title,
  p.name AS person,
  count(*) AS mentions
ORDER BY mentions DESC, person

The first statement performs a semantic-style narrowing step. The second statement uses only those result rows to expand into the graph and produce a relationship-oriented result.

Real Use Cases

Real Limitations And Tradeoffs