Click to copy

• 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.

Discover what readers are saying
topictale
Get easy to digest how-tos on ksqlDB
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like