-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[R2 SQL] Document JOINs, subqueries, and multi-table queries #30826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
389e634
[R2 SQL] Document JOINs, subqueries, and multi-table query support
Marcinthecloud 9197b6f
Update src/content/docs/r2-sql/reference/limitations-best-practices.mdx
Marcinthecloud f028f0f
Update src/content/docs/r2-sql/reference/limitations-best-practices.mdx
Marcinthecloud 4a52508
addressed netgusto's feedback
Marcinthecloud 04c1342
Merge branch 'r2sql-joins' of https://github.com/cloudflare/cloudflar…
Marcinthecloud ee09e84
Apply suggestion from @sejoker
sejoker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/content/changelog/r2-sql/2026-05-14-joins-subqueries-multi-table-queries.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| --- | ||
| title: R2 SQL now supports JOINs, subqueries, and multi-table queries | ||
| description: Join multiple Iceberg tables, use subqueries, and write multi-table CTEs in R2 SQL. | ||
| products: | ||
| - r2-sql | ||
| date: 2026-05-14 | ||
| --- | ||
|
|
||
| [R2 SQL](/r2-sql/) is Cloudflare's serverless, distributed SQL engine for querying [Apache Iceberg](https://iceberg.apache.org/) tables stored in [R2 Data Catalog](/r2/data-catalog/). R2 SQL runs directly on Cloudflare's global network with no infrastructure to manage, so you can analyze data in R2 without exporting it to an external warehouse. | ||
|
|
||
| R2 SQL now supports joining multiple Iceberg tables in a single query. You can combine tables with JOINs, filter with subqueries, and define multi-table CTEs to build complex analytical queries. | ||
|
|
||
| ## New capabilities | ||
|
|
||
| - **JOINs** — `INNER JOIN`, `LEFT JOIN`, `RIGHT JOIN`, `FULL OUTER JOIN`, `CROSS JOIN`, and implicit joins (comma-separated `FROM` with conditions in `WHERE`) | ||
| - **Subqueries** — `IN` / `NOT IN`, `EXISTS` / `NOT EXISTS`, scalar subqueries in `SELECT` / `WHERE` / `HAVING`, and derived tables (subqueries in `FROM`) | ||
| - **Multi-table CTEs** — `WITH` clauses can reference different tables and include JOINs | ||
| - **Self-joins** — join a table with itself using different aliases | ||
| - **Multi-way joins** — join three or more tables in a single query | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Two-table JOIN with aggregation | ||
|
|
||
| ```sql | ||
| SELECT z.domain, z.plan, COUNT(*) AS request_count | ||
| FROM my_namespace.zones z | ||
| INNER JOIN my_namespace.http_requests h ON z.zone_id = h.zone_id | ||
| WHERE z.plan = 'enterprise' | ||
| GROUP BY z.domain, z.plan | ||
| ORDER BY request_count DESC | ||
| LIMIT 20 | ||
| ``` | ||
|
|
||
| ### `EXISTS` subquery | ||
|
|
||
| ```sql | ||
| SELECT z.domain, z.plan | ||
| FROM my_namespace.zones z | ||
| WHERE EXISTS ( | ||
| SELECT 1 FROM my_namespace.firewall_events f | ||
| WHERE f.zone_id = z.zone_id AND f.action = 'block' | ||
| ) | ||
| ORDER BY z.domain | ||
| LIMIT 20 | ||
| ``` | ||
|
|
||
| ### Multi-table CTE with JOIN | ||
|
|
||
| ```sql | ||
| WITH top_zones AS ( | ||
| SELECT zone_id, COUNT(*) AS req_count | ||
| FROM my_namespace.http_requests | ||
| GROUP BY zone_id | ||
| ORDER BY req_count DESC | ||
| LIMIT 50 | ||
| ), | ||
| zone_threats AS ( | ||
| SELECT zone_id, COUNT(*) AS threat_count | ||
| FROM my_namespace.firewall_events | ||
| WHERE risk_score > 0.5 | ||
| GROUP BY zone_id | ||
| ) | ||
| SELECT tz.zone_id, tz.req_count, COALESCE(zt.threat_count, 0) AS threat_count | ||
| FROM top_zones tz | ||
| LEFT JOIN zone_threats zt ON tz.zone_id = zt.zone_id | ||
| ORDER BY tz.req_count DESC | ||
| LIMIT 20 | ||
| ``` | ||
|
|
||
| For the full syntax reference, refer to the [SQL reference](/r2-sql/sql-reference/). For performance guidance with joins, refer to [Limitations and best practices](/r2-sql/reference/limitations-best-practices/). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.