title: How to tell that two variables have different values in SPARQL
body: <p>I'm studying SPARQL and I have a doubt about queries. </p>
  
  <p>Suppose I have a simple ontology like the following</p>
  
  <pre><code>:Jack a :Worker ; :worksAt :Project1,:Project2
  :Bob  a :Worker ; :worksAt :Project2,:Project3
  :Mike a :Worker ; :worksAt :Project3,:Project1
  </code></pre>
  
  <p>Now I want to ask for the couple of workers who worked on the same project.
  If I try something like</p>
  
  <pre><code>SELECT ?x,?y
  WHERE
  {
      ?x :worksAt ?p
      ?y :worksAt ?p
  
  }
  </code></pre>
  
  <p>What happens is that the query also analyzes cases where <code>?x</code> and <code>?y</code> are the same resource, hence I have stuff like <code>[Jack,Jack]</code> in the results.</p>
  
  <p>If I do</p>
  
  <pre><code> SELECT ?x,?y
      WHERE
      {
          ?x :worksAt ?p
          ?y :worksAt ?p
          FILTER (?x != ?y)
      }
  </code></pre>
  
  <p>the query works properly, but for very complicated queries I find myself doing hundreds of <code>FILTERs</code> like that one.</p>
  
  <p>Is there a better way to specify that <code>?x</code> and <code>?y</code> must be different resources?
  Thank you in advance for your answers!</p>