liveBook · Manning

Where clause

As explained in Kafka Streams in Action, Second Edition

A WHERE clause is an SQL query clause that restricts returned records to those satisfying a Boolean condition.

A WHERE clause filters query results to rows whose Boolean condition is true. In a ksqlDB activity-leaders query, it can limit a live client subscription to users with more than 1,000 steps. section 11.3

Filter a live query

SELECT last_name, activity, total_steps FROM activity_leaders WHERE total_steps > 1000 EMIT CHANGES; The push query returns matching updates without storing these results. Adding LIMIT 10 caps the returned updates. section 11.3

A WHERE condition can inspect:

  • Regular columns defined by the stream or table, such as total_steps. section 11.3
  • ROWTIME, ROWPARTITION, and ROWOFFSET, which ksqlDB attaches to incoming Kafka records. section 11.3
  • A key lookup in a pull query, such as WHERE key_1 = 'Smith'. section 11.3
Listing 11.19 Push query with WHERE clause
SELECT,
  last_name, activity, total_steps
FROM activity_leaders
WHERE total_steps > 1000
EMIT CHANGES;

Inspect the complete filtered push-query listing. section 11.3

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Defines filtering, demonstrates comparisons and key lookup, and names pseudo-columns; stops short of enumerating every condition.
Examples
Uses activity leaders, total_steps greater than 1,000, ROWTIME filtering, and a key lookup for Smith.
What you can do after
Apply it via ksqlDB to filter continuous updates or point-in-time results by data and record metadata.
How it connects
Connects push queries, pull queries, streams, tables, materialized tables, Kafka topics, and pseudo-columns.

Also explained in

Compare how 7 books explain where clause →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.