title: What is the difference between UNION and EXISTS filters in a SPARQL query
body: <p>I'm experimenting with <a href="http://dbpedia.org/sparql" rel="nofollow noreferrer">DBpedia SPARQL endpoint</a> and I've noticed a difference between to similar queries using either a UNION or a EXISTS filter.</p>
  
  <pre><code>SELECT (COUNT(?w1) as ?nbWriter) WHERE {
      ?w1 a dbo:Writer; 
      dbo:spouse ?w2 .
      FILTER ( EXISTS {?w2 a dbo:Writer} || EXISTS {?w2 a yago:AmericanNovelists.} )
  }
  </code></pre>
  
  <p>produces result <code>nbWriters=371</code></p>
  
  <p>while query</p>
  
  <pre><code>SELECT (COUNT(?w1) as ?nbWriter) WHERE {
      ?w1 a dbo:Writer;
      dbo:spouse ?w2 .
      {?w2 a dbo:Writer.} 
      UNION
      {?w2 a yago:AmericanNovelists.} 
  }
  </code></pre>
  
  <p>produces result <code>nbWriters=414</code></p>
  
  <p>Why is there a difference between these two queries ? Are they not equivalent (see previous question and answer <a href="https://web.archive.org/web/20160814122326/http://answers.semanticweb.com:80/questions/22482/proper-way-to-add-or-clause-to-sparql-query" rel="nofollow noreferrer">Proper way to add OR clause to SPARQL query</a>) ? </p>