# Sql\_last\_value not working properly

**URL:** <https://discuss.elastic.co/t/sql-last-value-not-working-properly/227244>\
**Category:** Logstash\
**Created:** [April 9, 2020, 6:01am UTC](https://discuss.elastic.co/t/sql-last-value-not-working-properly/227244 "2020-04-09T06:01:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chelseia](https://avatars.discourse-cdn.com/v4/letter/c/d78d45/32.png) [@chelseia](https://discuss.elastic.co/u/chelseia)\
**Post date:** [April 9, 2020, 6:01am UTC](https://discuss.elastic.co/t/sql-last-value-not-working-properly/227244/1 "2020-04-09T06:01:12Z")

</div>

i am trying to ingest the records with following timestamps  
01.03.38.75894600  
01.03.38.88577300  
01.03.39.08149800  
.but before that I have successfully ingested 100 rec which having same timestamp.so no w i have my sql last\_value \_as 01.01.12.23410000.  
so when the next run comes the above 3 records are updating successfully. But instead of taking the last timestamp(01.03.39.08149800) as the sql\_last\_value it is assigning the first record (01.03.38.75894600).and in the next run the rest of the 2 records are ingesting again and it is continuning in this manner.can u pls tell how to resolve this.my cobfig file is shown below:

input{  
jdbc{  
clean\_run =\> true  
jdbc\_driver\_library =\> "C:/Program Files/SQL Developer 4/jdbc/lib/ojdbc8.jar"  
jdbc\_driver\_class =\> "Java::oracle.jdbc.driver.OracleDriver"  
jdbc\_connection\_string =\> "connection"  
jdbc\_user =\> ""  
jdbc\_password =\> "pwd"  
statement =\> "select \* from bucket\_truck where updated\_at \> :sql\_last\_value"  
tracking\_column =\> "updated\_at"  
tracking\_column\_type =\> "timestamp"  
use\_column\_value =\> true  
schedule =\> "\*/1 \* \* \* \*"  
}

}  
output{  
elasticsearch{  
hosts =\>"[http://localhost:9200](http://localhost:9200)"  
index =\>"ma1"  
document\_id =\>"%{pmd\_widget\_id}"  
document\_type =\> "doc"

```
}
stdout{}

```

}

---

<div class="post-metadata">

**Author:** ![jgabor](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@jgabor](https://discuss.elastic.co/u/jgabor)\
**Post date:** [April 9, 2020, 7:38am UTC](https://discuss.elastic.co/t/sql-last-value-not-working-properly/227244/2 "2020-04-09T07:38:56Z")

</div>

This looks like the problem I had two years ago: [JDBC to ElasticSearch: duplicate records?](https://discuss.elastic.co/t/jdbc-to-elasticsearch-duplicate-records/150153)

tldr: try to put an order\_by updated\_at to your query

---

<div class="post-metadata">

**Author:** ![chelseia](https://avatars.discourse-cdn.com/v4/letter/c/d78d45/32.png) [@chelseia](https://discuss.elastic.co/u/chelseia)\
**Post date:** [April 13, 2020, 9:30am UTC](https://discuss.elastic.co/t/sql-last-value-not-working-properly/227244/3 "2020-04-13T09:30:10Z")

</div>

thank you .Its working.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 11, 2020, 9:30am UTC](https://discuss.elastic.co/t/sql-last-value-not-working-properly/227244/4 "2020-05-11T09:30:31Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
