# Joins in Elastic Query

**URL:** <https://discuss.elastic.co/t/joins-in-elastic-query/178942>\
**Category:** Elasticsearch\
**Created:** [April 29, 2019, 1:33pm UTC](https://discuss.elastic.co/t/joins-in-elastic-query/178942 "2019-04-29T13:33:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![directproducteur](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@directproducteur](https://discuss.elastic.co/u/directproducteur)\
**Post date:** [April 29, 2019, 1:33pm UTC](https://discuss.elastic.co/t/joins-in-elastic-query/178942/1 "2019-04-29T13:33:17Z")

</div>

**Requirement** : Objective is to calculate the metrics which is equivalent to SQL Query below.

_SELECT COUNT(DISTINCT (required\_column\_name)) FROM table\_1 A INNER JOIN table\_1 B ON A.matching\_column\_name = B.matching\_column\_name WHERE A.distinguishing\_column\_name = 'distinguishing\_value\_A' AND B.distinguishing\_column\_name = 'distinguishing\_value\_B'._

Precisely an inner join on same table/index. (Example - [http://www.sqlservertutorial.net/sql-server-basics/sql-server-self-join/](http://www.sqlservertutorial.net/sql-server-basics/sql-server-self-join/)). After which, I would like to calculate the proportion of the matching column between the two classes. For example, 30 percent of class A are present in class B.

Thanks for your time!

**PS** : While surfing related to inner join, I got suggestions to use Nested Query. But, I am not very sure about the usage for my requirement. If the same can be used, it would be helpful to have a sample query which I could use going forward.

---

<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 27, 2019, 1:33pm UTC](https://discuss.elastic.co/t/joins-in-elastic-query/178942/2 "2019-05-27T13:33:21Z")

</div>

Closed on May 27, 2019, 1:33pm UTC

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