# Ksqldb EMIT FINAL

**URL:** <https://forum.confluent.io/t/ksqldb-emit-final/9092>\
**Category:** ksqlDB\
**Created:** [16 November 2023 10:41 UTC](https://forum.confluent.io/t/ksqldb-emit-final/9092 "2023-11-16T10:41:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![patharapon](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@patharapon](https://forum.confluent.io/u/patharapon)\
**Post date:** [16 November 2023 10:41 UTC](https://forum.confluent.io/t/ksqldb-emit-final/9092/1 "2023-11-16T10:41:15Z")

</div>

```auto
create table Prite_Dup_Table as SELECT 
AFTER -> ID as ID,
LATEST_BY_OFFSET(AFTER -> FIRST_NAME) as FIRST_NAME,
LATEST_BY_OFFSET(AFTER -> LAST_NAME) as LAST_NAME,
SUM(AFTER -> AMOUNT) as AMOUNT
FROM Prite_Dup
WINDOW TUMBLING (SIZE 1 SECONDS)
GROUP BY AFTER -> ID EMIT FINAL;

```

after use EMIT FINAL and insert duplicate data in 1 seconds but no output on SELECT command and topic  
Why EMIT FINAL no result on topic

---

<div class="post-metadata">

**Author:** ![dtroiano](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/dtroiano/32/1961_2.png) [@dtroiano](https://forum.confluent.io/u/dtroiano)\
**Post date:** [16 November 2023 14:12 UTC](https://forum.confluent.io/t/ksqldb-emit-final/9092/2 "2023-11-16T14:12:57Z")

</div>

This should work. What does the DDL for `Prite_Dup` look like? Are you using the record timestamps (default) or event time (more [here](https://docs.ksqldb.io/en/latest/concepts/time-and-windows-in-ksqldb-queries/#time-semantics) on time semantics)?

You might compare to the following `EMIT FINAL` example (based on [this](https://developer.confluent.io/tutorials/create-tumbling-windows/ksql.html) tumbling windows tutorial) to see EMIT FINAL working as expected and compare it to your setup. What’s different about them?

Create raw event stream:

```auto
CREATE STREAM movieratings (title VARCHAR, release_year INT, rating DOUBLE)
    WITH (kafka_topic='movieratings',
          partitions=1,
          value_format='avro');

```

Kick off windowed aggregation `EMIT FINAL` query:

```auto
SELECT title,
       COUNT(*) AS rating_count,
       WINDOWSTART AS window_start,
       WINDOWEND AS window_end, LATEST_BY_OFFSET(rating)
FROM movieratings
WINDOW TUMBLING (SIZE 1 SECONDS)
GROUP BY title
EMIT FINAL;

```

Repeatedly run the following insert statement to insert duplicate data with different record timestamps:

```auto
INSERT INTO movieratings (title, release_year, rating) VALUES ('Die Hard', 1998, 6.7);

```

You should see only one row emitted per window, and it should get emitted when the window closes (e.g., insert one row, count 2 seconds, and then insert another – at this point the first window closes and you’ll see the row emitted).

---

<div class="post-metadata">

**Author:** ![patharapon](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@patharapon](https://forum.confluent.io/u/patharapon)\
**Post date:** [22 November 2023 03:36 UTC](https://forum.confluent.io/t/ksqldb-emit-final/9092/3 "2023-11-22T03:36:06Z")

</div>

Hi dtroiano

I try to use your scenario command

1. Create raw stream

```auto
CREATE STREAM movieratings (title VARCHAR, release_year INT, rating DOUBLE)
    WITH (kafka_topic='movieratings',
          partitions=1,
          value_format='avro');

```

1. exec select window emit final

```auto
SELECT title,
       COUNT(*) AS rating_count,
       WINDOWSTART AS window_start,
       WINDOWEND AS window_end, LATEST_BY_OFFSET(rating)
FROM movieratings
WINDOW TUMBLING (SIZE 1 SECONDS)
GROUP BY title
EMIT FINAL;

```

1. select raw stream for compare

```auto
select * from movieratings emit changes;

```

1. try to insert into

round 1

```auto
INSERT INTO movieratings (title, release_year, rating) VALUES ('Die Hard', 1998, 6.7);

```

round 2

```auto
INSERT INTO movieratings (title, release_year, rating) VALUES ('Die Hard', 1998, 6.7);
INSERT INTO movieratings (title, release_year, rating) VALUES ('Die Hard', 1998, 6.7);

```

result from

```auto
select * from movieratings emit changes;

```

have 3 row because we insert into 3 row in 2 round

```auto
SELECT title,
       COUNT(*) AS rating_count,
       WINDOWSTART AS window_start,
       WINDOWEND AS window_end, LATEST_BY_OFFSET(rating)
FROM movieratings
WINDOW TUMBLING (SIZE 1 SECONDS)
GROUP BY title
EMIT FINAL;

```

from EMIT FINAL no result of both round  
Why no output on emit final?

I use ksqlDB 7.5.0

 ![image](https://us1.discourse-cdn.com/flex019/uploads/confluentcommunity/original/2X/0/0b1cf2639bb54381dc4e1eade8a02f837155f97e.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/confluentcommunity/original/1X/c49438c90c9df282e9996fdf6971be890c71b65a.svg) [@system](https://forum.confluent.io/u/system)\
**Post date:** [16 December 2023 10:41 UTC](https://forum.confluent.io/t/ksqldb-emit-final/9092/4 "2023-12-16T10:41:56Z")

</div>

This topic was automatically closed after 30 days. New replies are no longer allowed.
