Click to copy
Tables • Reviewed for ksqlDB 0.29
How to Create Table from Query in ksqlDB
To create a table from a query, use the GROUP BY
clause:
CREATE TABLE top_sales_by_department
AS SELECT
department,
max(sales)
FROM sales_records
GROUP BY department
EMIT CHANGES;
The fields in the GROUP BY
clause will be used as the key fields for the table.
This statement will create a materialized table that runs a persistent query to keep the state up to date with the sales_records
source.
Was this article helpful?