Denigma
hevok @hevok February 23, 2013
Tutorial #coding #exclusion #programing #query

MINUS

The [MINUS](/blog/676/) qualifier allows to exclude certain data.

Given a database with persons we have a given name and family name and one wants to nothing else than all triples, but not Triples that fulfill a specified condition, e.g. one do not want that the given name of any Resource or Subject has a certain Value. So the result will contain only Triples where the results has other names than that was specified.

  • Filtering of query solutions by removing possible solutions with [MINUS](/blog/676/)

Data:

@prefix : ](http://example.com>)] .
@prefix foaf: 

:hevok foaf:givenName "Hevok" ;
       foaf:familyName "n/a" .

:eva foaf:givenName "EVA"
     foaf:familyName "unknown" .

:herbert foaf:givenName "Herbert" ;
         foaf:familyName "Kaebie" .

Query:

PREFIX : ](http://example/>)]
PREFIX foaf: ](http://xmlns.com/foaf/0.1/>)]
[SELECT](/blog/651/) DISTINCT ?s
WHERE {
    ?s ?p ?o .
    [MINUS](/blog/676/) {
        ?s foaf:givenName "Herbert" .
    }
 }

Result:

?s
:hevok
:eva