# How to write sub query in esql

**URL:** <https://discuss.elastic.co/t/how-to-write-sub-query-in-esql/233227>\
**Category:** Kibana\
**Tags:** elastic-stack-sql, canvas\
**Created:** [May 19, 2020, 3:16am UTC](https://discuss.elastic.co/t/how-to-write-sub-query-in-esql/233227 "2020-05-19T03:16:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arureddy](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@arureddy](https://discuss.elastic.co/u/arureddy)\
**Post date:** [May 19, 2020, 3:16am UTC](https://discuss.elastic.co/t/how-to-write-sub-query-in-esql/233227/1 "2020-05-19T03:16:31Z")

</div>

Hi,

```
I am trying to get results from alias index (alias_index1_index2 = index1 and index2) if values of two columns from different indexes matches. Looks like joins or sub queries are not support ed completely. Could any one tried or let me know how to achieve .

Query:

```

```auto
SELECT col1, col2 FROM alias_index1_index2 WHERE col2 IS NOT NULL AND timestamp < NOW() AND timestamp > NOW() - INTERVAL 30 MINUTE AND col1 = col2 

```

```auto
Error:
  [essql] > Unexpected error from Elasticsearch: [sql_illegal_argument_exception] Line 1:232: Comparisons against variables are not (currently) supported; 

```

```
Thanks,
Areddy
```

---

<div class="post-metadata">

**Author:** ![matriv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matriv/32/43656_2.png) [@matriv](https://discuss.elastic.co/u/matriv)\
**Post date:** [May 19, 2020, 3:59pm UTC](https://discuss.elastic.co/t/how-to-write-sub-query-in-esql/233227/2 "2020-05-19T15:59:33Z")

</div>

Indeed `col1 = col2 ` is not currently supported.  
Joins are not supported currently either and currently there is [only limited support for subqueries](https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-limitations.html#_using_a_sub_select).

I don't see a workaround for your case.

---

<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:** [June 16, 2020, 3:59pm UTC](https://discuss.elastic.co/t/how-to-write-sub-query-in-esql/233227/3 "2020-06-16T15:59:34Z")

</div>

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