Relational and graph in one query
CoraDB is one database engine for relational and graph data, not two engines side by side. A graph is stored in vertex tables (nodes) and edge tables (relationships), and these are tables like any other. That means:
- Vertex and edge tables can be read and changed with ordinary SQL;
- A
MATCHgraph pattern is just another source in theFROMclause of aSELECT, so one statement can traverse the graph and join relational tables, then filter, group, sort and aggregate the result; - Inserts and updates of rows, nodes and edges take part in the same transaction.
The examples below run on the e-commerce sample database: orders and order_items are relational tables, customer, product, category, brand and city are vertex tables, and likes, follows, part_of and resides_in are edge tables. The relational tables refer to vertices through ordinary foreign keys (orders.customer_id → customer.id, order_items.product_id → product.id).
Vertex tables are tables
Section titled “Vertex tables are tables”A vertex table can be queried without any graph syntax. The products that cost more than 100:
SELECT name, unit_price, units_in_stockFROM productWHERE unit_price > 100ORDER BY unit_price DESCLIMIT 3;| name | unit_price | units_in_stock |
|---|---|---|
| Côte de Blaye | 263.50 | 17 |
| Thüringer Rostbratwurst | 123.79 | 0 |
It also joins relational tables like any table. The customers with the most orders (customer is a vertex table, orders a relational table):
SELECT c.company_name AS customer, COUNT(*) AS ordersFROM orders o JOIN customer c ON c.id = o.customer_idGROUP BY c.id, c.company_nameORDER BY orders DESC, customerLIMIT 3;| customer | orders |
|---|---|
| Mayer, Carroll and Owens | 40 |
| Young and Sons | 40 |
| Kelly Ltd | 39 |
A graph pattern next to tables in FROM
Section titled “A graph pattern next to tables in FROM”A MATCH pattern can be listed in the FROM clause together with relational tables and joined to them in WHERE. The best-selling categories: the graph says which category a product belongs to (part_of edge), the relational order_items table says how many units were sold:
SELECT cat.name AS category, SUM(oi.quantity) AS units_soldFROM MATCH (p:product)-[:part_of]->(cat:category), order_items oiWHERE oi.product_id = p.idGROUP BY cat.nameORDER BY units_sold DESCLIMIT 5;| category | units_sold |
|---|---|
| Shorts | 6528 |
| Tees | 6232 |
| Erin Recommends | 5843 |
| Hoodies & Sweatshirts | 5779 |
| Jackets | 5394 |
JOIN … ON with a graph pattern
Section titled “JOIN … ON with a graph pattern”The pattern can also be the right side of a JOIN. The cities with the most orders: orders is joined to the customers of the resides_in pattern, which gives each customer's city:
SELECT ci.name AS city, COUNT(*) AS orders, SUM(o.shipping_cost) AS shippingFROM orders o JOIN MATCH (c:customer)-[:resides_in]->(ci:city) ON c.id = o.customer_idGROUP BY ci.nameORDER BY orders DESCLIMIT 5;| city | orders | shipping |
|---|---|---|
| Portland | 113 | 1924.59 |
| San Francisco | 103 | 1804.23 |
| Elgin | 102 | 1760.51 |
| London | 102 | 1576.63 |
| Kirkland | 101 | 1797.71 |
Graph signals and purchases together
Section titled “Graph signals and purchases together”Edges often record behaviour (a customer likes a product, follows a brand) while relational tables record transactions. One query can compare them. The customers who bought the most of the products they like:
SELECT c.company_name AS customer, COUNT(DISTINCT p.id) AS liked_and_boughtFROM MATCH (c:customer)-[:likes]->(p:product), orders o, order_items oiWHERE o.customer_id = c.id AND oi.order_id = o.id AND oi.product_id = p.idGROUP BY c.company_nameORDER BY liked_and_bought DESC, customerLIMIT 3;| customer | liked_and_bought |
|---|---|
| Harris, Hernandez and Hancock | 3 |
| Moore-Anderson | 3 |
| Simpson-Atkins | 3 |
Relational results as input for a graph query
Section titled “Relational results as input for a graph query”A common table expression can compute a relational result first and feed it to a pattern. The Nike followers who order the most:
WITH spend AS ( SELECT customer_id, COUNT(*) AS orders, SUM(shipping_cost) AS shipping FROM orders GROUP BY customer_id)SELECT c.company_name AS customer, s.orders, s.shippingFROM MATCH (c:customer)-[:follows]->(b:brand), spend sWHERE b.name = 'Nike' AND s.customer_id = c.idORDER BY s.orders DESC, customerLIMIT 5;| customer | orders | shipping |
|---|---|---|
| Mayer, Carroll and Owens | 40 | 653.14 |
| Kelly Ltd | 39 | 638.48 |
| Smith-Williams | 25 | 442.54 |
| Murphy, Nelson and Donovan | 20 | 292.04 |
| Murray Ltd | 20 | 383.64 |
Rows, nodes and edges in one transaction
Section titled “Rows, nodes and edges in one transaction”Changes to relational tables, vertex tables and edge tables are ordinary DML in the same transaction: they are committed or rolled back together. An order, its order line and a new likes edge:
INSERT INTO orders (id, customer_id, order_date, shipping_cost, ship_address)VALUES (90001, 1, DATE '2026-11-19', 4.90, '12 Main Street, Portland');
INSERT INTO order_items (order_id, product_id, quantity, discount_pct)VALUES (90001, 5, 1, 0);
INSERT EDGE FROM (SELECT c FROM customer c WHERE c.id = 1) TO (SELECT p FROM product p WHERE p.id = 5)INTO likes VALUES (DATETIME '2026-11-19 10:00:00');
COMMIT;Before the COMMIT, the same session already sees all three changes, in one query:
SELECT c.company_name AS customer, p.name AS product, l.since, oi.quantityFROM MATCH (c:customer)-[l:likes]->(p:product), order_items oiWHERE c.id = 1 AND p.id = 5 AND oi.order_id = 90001 AND oi.product_id = p.id;| customer | product | l.since | quantity |
|---|---|---|---|
| Woodward, Brown and Morton | Chef Antons Gumbo Mix | 2026-11-19 10:00:00.000 | 1 |
A ROLLBACK instead of the COMMIT removes the order, the order line and the edge together.
See also
Section titled “See also”- SELECT: the full syntax of the statement that hosts
MATCH. - MATCH clause (graph patterns): node and edge patterns, directions, variable-length and shortest paths, path variables.
- Graph functions:
NODES,RELATIONSHIPS,LABELand the JSON graph functions. - Graph types and CREATE VERTEX / EDGE TABLE.
- Tutorial: tables and graphs in one database.