# SQL “where not exists” equivalent for Elastic

**URL:** <https://discuss.elastic.co/t/sql-where-not-exists-equivalent-for-elastic/170934>\
**Category:** Elasticsearch\
**Created:** [March 5, 2019, 2:57pm UTC](https://discuss.elastic.co/t/sql-where-not-exists-equivalent-for-elastic/170934 "2019-03-05T14:57:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CraigMc](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@CraigMc](https://discuss.elastic.co/u/CraigMc)\
**Post date:** [March 5, 2019, 2:57pm UTC](https://discuss.elastic.co/t/sql-where-not-exists-equivalent-for-elastic/170934/1 "2019-03-05T14:57:45Z")

</div>

Hello,

I have a set of stages I am logging. A GUID is on each record to tie the stage together.  
Example:

Guid Stage  
1 Stage 1  
1 Stage 2  
1 Stage 3  
1 Stage 4  
1 Stage 5  
2 Stage 1  
2 Stage 2  
2 Stage 3  
2 Stage 4  
2 Stage 5

I am looking to put a visual together on any GUID which has any missing stages.  
In SQL I would use something along the lines of:

select \* from tbl as a  
where stage = 1 and  
not exists (  
select \* from tbl as b where  
stage = 5 and a.guid = b.guid  
)

Any advice on how to achieve this in elastic/kibana?

---

<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:** [April 2, 2019, 2:57pm UTC](https://discuss.elastic.co/t/sql-where-not-exists-equivalent-for-elastic/170934/2 "2019-04-02T14:57:50Z")

</div>

Closed on April 2, 2019, 2:57pm UTC

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