Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cypher is Neo4j’s declarative graph query language. You describe nodes with parentheses, relationships with square brackets, and paths by connecting those patterns. This cheat sheet covers the query forms you use most often to read, create, update, delete, batch-process, and tune graph data.

Cypher syntax at a glance

  • Node: (n), optionally with a variable, label, and properties such as (p:Person {name: $name}).
  • Relationship: -[r:ACTED_IN]->, with an optional variable, type, direction, and properties.
  • Path: a connected pattern such as (p)-[:ACTED_IN]->(m).
  • Parameters: values such as $name are supplied separately by the driver or client.
  • Keywords: Cypher keywords are not case-sensitive; variable names are case-sensitive.

Cypher supports clauses for reading, writing, transforming, and removing graph data. A query is usually a pipeline: one clause produces rows that the next clause consumes.

Read a pattern with MATCH

MATCH (p:Person {name: $name})-[:ACTED_IN]->(m:Movie)
RETURN m.title AS title
ORDER BY title

MATCH finds rows that satisfy a graph pattern. The label Person, relationship type ACTED_IN, and label Movie constrain what can match. RETURN chooses the output columns, while ORDER BY sorts them.

Match nodes, relationships, and paths

MATCH (p:Person)-[r:ACTED_IN]->(m:Movie)
RETURN p.name, r, m.title

Use a variable such as p, r, or m when you need to return it, filter on it, or use it in a later clause. Direction matters: -> is outgoing, <- is incoming, and -[]- matches either direction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Use OPTIONAL MATCH when a pattern may be missing

MATCH (p:Person {name: $name})
OPTIONAL MATCH (p)-[r:DIRECTED]->(movie)
RETURN p.name, r, movie

OPTIONAL MATCH keeps the row from the required part of the query and supplies null for the missing pattern. In this example, the person must exist, but a directed movie does not have to exist.

Keep WHERE beside the pattern it filters

MATCH (p:Person)
WHERE p.country = $country
OPTIONAL MATCH (p)-[:DIRECTED]->(movie)
WHERE movie.released >= $year
RETURN p.name, movie.title

WHERE is a subclause of MATCH, OPTIONAL MATCH, and WITH. Place it immediately after the clause whose pattern or values it filters. Moving a predicate across an optional match can change whether rows are preserved or eliminated.

Transform rows with WITH

MATCH (c:Customer)-[:BUYS]->(p:Product)
WITH c, count(p) AS purchases
WHERE purchases > 2
RETURN c.name, purchases
ORDER BY purchases DESC

WITH is a pipeline boundary. It can aggregate, rename, calculate, sort, and filter values before the next stage. Only variables named in WITH continue to the following clause; use WITH * when you intentionally carry every variable forward.

Calculate values between stages

MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WITH p, collect(m.title) AS films
RETURN p.name, films

Aggregating functions such as count() and collect() group rows at the WITH or RETURN boundary. A variable omitted from that boundary is no longer available in the normal outer query scope.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Create new graph data with CREATE

CREATE (p:Person {name: $name})
RETURN p

CREATE always creates the specified pattern each time the clause executes. It does not check whether an equivalent node or relationship already exists.

Create a relationship between existing nodes

MATCH (p:Person {id: $personId}), (m:Movie {id: $movieId})
CREATE (p)-[:ACTED_IN {role: $role}]->(m)
RETURN p, m

Separate the lookup from the write when the endpoints already exist. If the query can run more than once, decide explicitly whether duplicate relationships are acceptable or whether MERGE is more appropriate.

Match or create with MERGE

MERGE (p:Person {email: $email})
ON CREATE SET p.createdAt = datetime()
ON MATCH SET p.lastSeen = datetime()
RETURN p

MERGE matches the whole pattern or creates it when that pattern is absent. Its identifying pattern is therefore important: include only the properties that define the entity you intend to find or create. ON CREATE runs for a newly created match; ON MATCH runs when an existing match is found.

MERGE is not a universal uniqueness guarantee under every concurrency and schema configuration. Use an appropriate uniqueness constraint and design the identifying pattern deliberately.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Update properties with SET and REMOVE

MATCH (p:Person {id: $id})
SET p.city = $city,
    p.updatedAt = datetime()
RETURN p

Use SET to assign properties or labels. To remove a property, use REMOVE (or assign null where that behavior is appropriate for your application and version).

MATCH (p:Person {id: $id})
REMOVE p.temporaryFlag
RETURN p

Expand lists and batches with UNWIND

UNWIND $rows AS row
MERGE (p:Person {id: row.id})
SET p.name = row.name
RETURN count(p) AS processed

UNWIND turns each element of a list into a row. It is useful for parameterized batches, imports, and turning collected values back into rows. Validate input shape and choose transaction sizes appropriate to the data volume; very large imports need an operations and batching strategy rather than one unbounded transaction.

Delete nodes and relationships safely

Delete a relationship

MATCH (p:Person)-[r:KNOWS]->(friend:Person)
WHERE p.id = $personId AND friend.id = $friendId
DELETE r

DELETE removes the matched entity. A node that still has relationships generally cannot be deleted with plain DELETE.

Delete a node and its connected relationships

MATCH (p:Person {id: $id})
DETACH DELETE p

DETACH DELETE removes the node and all relationships connected to it. Treat broad forms such as MATCH (n) DETACH DELETE n as destructive: they remove all graph data. For large deletion jobs, use transactional batching; deleting data does not remove indexes or schema definitions.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Shape, order, and paginate results

MATCH (m:Movie)
RETURN m.title AS title, m.released AS year
ORDER BY year DESC, title
SKIP $offset
LIMIT $pageSize

RETURN defines the result columns. Use aliases to give client code stable names. Apply ORDER BY before SKIP and LIMIT when you need deterministic pagination, and return only the fields the application needs.

Combine result sets with UNION

MATCH (p:Person)
RETURN p.name AS name
UNION
MATCH (c:Customer)
RETURN c.name AS name

UNION combines results and removes duplicate rows. Use UNION ALL when duplicates are meaningful or deduplication is unnecessary. Each branch must return the same number of columns with compatible names and types.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Inspect and tune a query

Use parameters

Parameterize values such as IDs, names, dates, and lists instead of concatenating them into query text. This improves safety and lets the database reuse plans more effectively.

Compare EXPLAIN and PROFILE

EXPLAIN
MATCH (p:Person {email: $email})
RETURN p

EXPLAIN shows the planned operators without executing the query. Replace it with PROFILE when you need runtime operators and measurements from an execution. Use those observations, result size, and your workload to decide whether a change helps; an index or syntax change does not guarantee a particular speedup.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Indexes and bounded traversals

  • Use an appropriate index for frequently searched properties. Neo4j documents range (the default), text, point, and token lookup indexes, as well as full-text and vector indexes.
  • Bound variable-length patterns when possible. An unbounded traversal can explore far more of the graph than intended.
  • Filter early, carry only required variables through WITH, and return only required fields.
  • Check the plan for accidental cartesian products, label scans, or unexpectedly high row counts.

Cypher version notes

Available syntax depends on the Neo4j release and the Cypher version selected by that release. The current documentation describes CYPHER 25 for servers running Neo4j 2025.06 or later, and CYPHER 5 as the Cypher 5 behavior from the Neo4j 2025.06 release. Verify your server version and its matching manual before using version-sensitive syntax.

Newer references include forms such as FILTER, dynamic labels and relationship types, and WHEN. Do not assume those forms work on older deployments; test them against the target version or use the syntax documented for that server.

Quick comparison of commonly confused clauses

Use case Choose Effect
Required versus optional pattern MATCH / OPTIONAL MATCH MATCH removes rows without a match; OPTIONAL MATCH preserves the row and returns null for the missing part.
Always create versus match-or-create CREATE / MERGE CREATE creates the pattern every time; MERGE matches the complete pattern or creates it.
Deduplicate versus preserve duplicates UNION / UNION ALL UNION removes duplicate rows; UNION ALL keeps them.
Delete one entity versus its connected relationships too DELETE / DETACH DELETE DETACH DELETE removes a node’s connected relationships as well.

Where to continue learning

Neo4j GraphAcademy’s free Cypher Fundamentals course covers reading and writing graph data. Its intermediate Cypher material includes filtering, variable-length traversal, WITH, subqueries, UNWIND, and parameters. For a book-length treatment, Neo4j’s recommended-books page lists Graph Data Processing with Cypher by Ravindranatha Anthapu, published by Packt; verify the edition and current availability before buying.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.