title: SPARQL Query, select everything except things that match?
body: <p>I am getting comfortable writing regular queries in SPARQL, but I'm still having trouble with fancier stuff.  My latest problem is trying to select everything except stuff that matches the where clause.  For instance, say I want to find all the husbands who like a car color that their wife doesn't like (I'm working on a proprietary model, so excuse the example and just trust that it makes sense in the real model).</p>
  
  <p>I might have:</p>
  
  <pre><code>&lt;bob&gt; &lt;spouse&gt; &lt;alice&gt;
  &lt;bob&gt; &lt;likes&gt; &lt;red&gt;
  &lt;alice&gt; &lt;likes&gt; &lt;red&gt;
  &lt;carl&gt; &lt;spouse&gt; &lt;dorothy&gt;
  &lt;carl&gt; &lt;likes&gt; &lt;blue&gt;
  &lt;dorothy&gt; &lt;likes&gt; &lt;yellow&gt;
  &lt;eric&gt; &lt;spouse&gt; &lt;fannie&gt;
  &lt;eric&gt; &lt;likes&gt; &lt;black&gt;
  </code></pre>
  
  <p>What's the query that selects carl and eric, but not bob?  Bonus points if you can select blue and black in the same query.  Selecting bob would be simply:</p>
  
  <pre><code>select ?husband ?color where {?husband &lt;spouse&gt; ?wife . ?husband &lt;likes&gt; ?color . ?wife &lt;likes&gt; ?color}
  </code></pre>
  
  <p>What I'm looking for is:</p>
  
  <pre><code>select ?husband ?color where {?husband &lt;spouse&gt; ?wife . ?husband &lt;likes&gt; ?color . NOT (?wife &lt;likes&gt; ?color)}
  </code></pre>
  
  <p>but obviously that's wrong.  So what's right?</p>