Suppose we have a dataset that looks like this:
:person :wantsCD :cd1; :wantsCD :cd2 .
:storeA :sellsCD :cd1; sellsCD :cd2; sellsCD :cd3 .
:storeB :sellsCD :cd1; sellsCD :cd10; sellsCD :cd100 .
I'm interested in finding the stores that sell all the CD's :person
wants, i.e. (:storeA
). Is it possible to get this result with a SPARQL query? The query should also work when the number of CD's the :person
wants is unknown at runtime. I tried:
SELECT DISTINCT ?store ?cd
WHERE {
:person :wantsCD ?cd.
?store :sellsCD ?cd.
}
but this returns both :storeA
and :storeB
, since :storeB
also sells :cd1
.