query-ca8d5b984338c79326650e5679a9b80d
A set of cat breeds along with the cats that benlong to ).contribs • talk (Bilalox01 comment was added byunsignedThe preceding – Hello. I am trying to query all the cats breeds (wd:Q43577) along with the list of cats that belong to. Below, you will find my solution. The result of my solution is not relevant and contains a redundancy. Therefore, I need your help to find the best solution. Thanks.
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?CatsBreedsID ?CatsBreedsName ?CategoryID ?CategoryName ?CatsID ?CatsName where {
?CatsBreedsID wdt:P31 wd:Q43577.
OPTIONAL{
?CatsBreedsID wdt:P279 ?CategoryID.
?CatsID wdt:P31 ?CategoryID.
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
?CatsBreedsID rdfs:label ?CatsBreedsName .
?CategoryID rdfs:label ?CategoryName .
?CatsID rdfs:label ?CatsName.
}
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v2("?CategoryID"):::projected
v5("?CategoryName"):::projected
v1("?CatsBreedsID"):::projected
v4("?CatsBreedsName"):::projected
v3("?CatsID"):::projected
v6("?CatsName"):::projected
c5(["bd:serviceParam"]):::iri
c7(["en"]):::literal
c2(["wd:Q43577"]):::iri
v1 --"wdt:P31"--> c2
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."wdt:P279".-> v2
v3 --"wdt:P31"--> v2
end
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c5 --"wikibase:language"--> c7
v1 --"rdfs:label"--> v4
v2 --"rdfs:label"--> v5
v3 --"rdfs:label"--> v6
end