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
Receive periodic ksqlDB how-tos
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like

We use cookies to improve your experience, as described in our Cookies Policy. By using this website you agree to its usage.