# ORDER BY in SQL query for Logstash JDBC Input

**URL:** <https://discuss.elastic.co/t/order-by-in-sql-query-for-logstash-jdbc-input/41252>\
**Category:** Logstash\
**Created:** [February 9, 2016, 8:43am UTC](https://discuss.elastic.co/t/order-by-in-sql-query-for-logstash-jdbc-input/41252 "2016-02-09T08:43:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Architha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/architha/32/92477_2.png) [@Architha](https://discuss.elastic.co/u/Architha)\
**Post date:** [February 9, 2016, 8:43am UTC](https://discuss.elastic.co/t/order-by-in-sql-query-for-logstash-jdbc-input/41252/1 "2016-02-09T08:43:17Z")

</div>

Hi All,

When `Order by` is used in the SQL Query we give as a JDBC input to Logstash , will the order be maintained as we have mentioned in the query ? As of now i see that the document is ordered according to my query but i'm doubtful if it happens this way always .  
Kindly Clarify .  
Thanks in Advance!

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 9, 2016, 10:10am UTC](https://discuss.elastic.co/t/order-by-in-sql-query-for-logstash-jdbc-input/41252/2 "2016-02-09T10:10:41Z")

</div>

Maintained where, after the documents end up in Elasticsearch? No, you can't rely on any order there.

---

<div class="post-metadata">

**Author:** ![Architha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/architha/32/92477_2.png) [@Architha](https://discuss.elastic.co/u/Architha)\
**Post date:** [February 9, 2016, 10:44am UTC](https://discuss.elastic.co/t/order-by-in-sql-query-for-logstash-jdbc-input/41252/3 "2016-02-09T10:44:09Z")

</div>

Yes , maintained after documents are on Elastic Search.  
Thanks for the quick reply !

---

<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:** [July 6, 2017, 5:12am UTC](https://discuss.elastic.co/t/order-by-in-sql-query-for-logstash-jdbc-input/41252/4 "2017-07-06T05:12:31Z")

</div>


