<docbook><section><title>VirtTipsAndTricksGuideSPARQLMINUS</title><title> How Do I use MINUS in a SPARQL query?</title> How Do I use MINUS in a SPARQL query?
<para> Virtuoso supports the MINUS function of SPARQL 1.1, as shown below --</para>
<programlisting>SQL&gt; SPARQL 
SELECT COUNT(*) 
WHERE 
  { 
    { ?s ?p &quot;Novosibirsk&quot; } MINUS { ?s ?p &quot;???????????&quot; }
  }

callret-0
INTEGER
 313
No. of rows in result: 1 
</programlisting><para> <ulink url="http://lod.openlinksw.com/sparql?default-graph-uri=&amp;query=SELECT+COUNT%28*%29+%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%7B+%3Fs+%3Fp+%22Novosibirsk%22+%7D+MINUS+%7B+%3Fs+%3Fp+%22%D0%9D%D0%BE%D0%B2%D0%BE%D1%81%D0%B8%D0%B1%D0%B8%D1%80%D1%81%D0%BA%22+%7D%0D%0A++%7D&amp;should-sponge=&amp;format=text%2Fhtml&amp;CXML_redir_for_subjs=121&amp;CXML_redir_for_hrefs=&amp;timeout=15000&amp;debug=on">View the results</ulink> of the query execution on the <ulink url="http://lod.openlinksw.com">LOD</ulink> instance.</para>
<para>This query is equivalent to the following query, also conforming to SPARQL 1.1 --</para>
<programlisting>SQL&gt; SPARQL 
SELECT COUNT(*) 
WHERE 
  {
    ?s ?p &quot;Novosibirsk&quot;  FILTER NOT EXISTS { ?s ?p &quot;???????????&quot; } 
  }

callret-0
INTEGER
313
No. of rows in result: 1 
</programlisting><para><ulink url="http://lod.openlinksw.com/sparql?default-graph-uri=&amp;query=SELECT+COUNT%28*%29+%0D%0AWHERE+%0D%0A++%7B%0D%0A++++%3Fs+%3Fp+%22Novosibirsk%22++FILTER+NOT+EXISTS+%7B+%3Fs+%3Fp+%22%D0%9D%D0%BE%D0%B2%D0%BE%D1%81%D0%B8%D0%B1%D0%B8%D1%80%D1%81%D0%BA%22+%7D+%0D%0A++%7D&amp;should-sponge=&amp;format=text%2Fhtml&amp;CXML_redir_for_subjs=121&amp;CXML_redir_for_hrefs=&amp;timeout=15000&amp;debug=on">View the results</ulink> of the query execution on the <ulink url="http://lod.openlinksw.com">LOD</ulink> instance.</para>
<bridgehead class="http://www.w3.org/1999/xhtml:h2">Related</bridgehead>
<itemizedlist mark="bullet" spacing="compact"><listitem><ulink url="VirtTipsAndTricksGuide">Virtuoso Tips and Tricks Collection</ulink> </listitem>
<listitem><ulink url="http://docs.openlinksw.com/virtuoso/rdfsparql.html">Virtuoso Documentation</ulink> </listitem>
</itemizedlist></section></docbook>