title: How to match by id when using ORMLite Where Not Exists
body: <p>I'm building my query using the advice from <a href="https://stackoverflow.com/questions/9294586/does-ormlite-support-sql-exists">Does ORMLITE support SQL EXISTS?</a></p>
  
  <pre><code>public List&lt;Crag&gt; getAllCragsWithLocation() {
      QueryBuilder&lt;Crag, Integer&gt; cragQueryBuilder = _helper.getCragDao().queryBuilder();
      QueryBuilder&lt;CragLocation, Integer&gt; cragLocationQueryBuilder = _helper.getCragLocationDao().queryBuilder();
          try {
              cragLocationQueryBuilder.where().eq("locationType", 0);
              cragQueryBuilder.where().exists(cragLocationQueryBuilder);
              return cragQueryBuilder.query();
          } catch (Exception e) {
              Log.e(TAG,e.toString());
              return new ArrayList&lt;Crag&gt;();
          } 
  }
  </code></pre>
  
  <p>This returns all crags regardless of if they have a cragLocation so long as there are any cragLocation with a locationType of 0. Which is understandable...</p>
  
  <p>In the example linked above...</p>
  
  <pre><code>QueryBuilder&lt;Visit, Integer&gt; visitQb = visitDao.queryBuilder();
  visitQb.where().eq(Visit.CLIENT_ID_FIELD, client.getId());
  QueryBuilder&lt;Client, Integer&gt; clientQb = clientDao.queryBuilder();
  clientQb.where().exists(visitQb);
  List&lt;Client&gt; results = clientQb.query();
  </code></pre>
  
  <p>I guess the query is linking to the id of a specific client or perhaps more clearly</p>
  
  <pre><code>select * from client c
      where EXISTS (select * from visit v where c._id = v.client_id)
  </code></pre>
  
  <p>in my case</p>
  
  <pre><code>select * from Crag c
      where EXISTS (select * from CragLocation cl where c.id = cl.crag_id)
  </code></pre>
  
  <p>So my final query would be:</p>
  
  <pre><code>select * from Crag c
      where EXISTS (select * from CragLocation cl where c.id = cl.crag_id and cl.location_type = 0)
  </code></pre>