query-f6f66e40618bf805b25607312a5ffb69

rq turtle/ttl

GROUP_CONCAT and returning values before filteringHello, I am rather new to SPARQL and would be thankful if someone could help me out. I would like to query Wikidata for information about Renaissance painters and then also return what other occupations they had. In the query below, GROUP_CONCAT works with the movement part, but I couldn't get it to work for the occupations. . But I don't really know how it is supposed to be done. https://www.wikidata.org/wiki/Q7793How can I query for the occupation "painter", but then also return all other values that person has listed under occupations? I know that "FILTER(?occupation IN(wd:Q1028181))" is part of the problem, because like this it ONLY returns "painter", even if the person has multiple occupations, such as for

Use at

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 DISTINCT ?item ?itemLabel 
(GROUP_CONCAT(DISTINCT ?occupation; SEPARATOR = ",") AS ?occupationUID) 
(GROUP_CONCAT(DISTINCT ?occupationLabel; SEPARATOR = ",") AS ?occupations) 
(GROUP_CONCAT(DISTINCT ?movementLabel; SEPARATOR = ",") AS ?movements) 

WHERE {
  ?item wdt:P106 ?occupation;
        wdt:P135 ?movement;
  FILTER(?movement IN(wd:Q4692, wd:Q1472236, wd:Q1474884, wd:Q979160))
  FILTER(?occupation IN(wd:Q1028181))
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
    ?item rdfs:label ?itemLabel.
    ?occupation rdfs:label ?occupationLabel.
    ?movement rdfs:label ?movementLabel.

  }
}
GROUP BY ?item ?itemLabel

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?item"):::projected v4("?itemLabel"):::projected v2("?movement") v6("?movementLabel"):::projected v9("?movements") v1("?occupation"):::projected v5("?occupationLabel"):::projected v7("?occupationUID") v8("?occupations") c9(["bd:serviceParam"]):::iri c11(["#91;AUTO_LANGUAGE#93;,en"]):::literal f0[["?occupation = 'wd:Q1028181'"]] f0 --> v1 list0c4(["wd:Q979160"]):::iri list0c1(["wd:Q4692"]):::iri list0c3(["wd:Q1474884"]):::iri list0c2(["wd:Q1472236"]):::iri list0c1 --o f1 list0c2 --o f1 list0c3 --o f1 list0c4 --o f1 f1[[" in "]] f1 --> v2 v3 --"wdt:P106"--> v1 v3 --"wdt:P135"--> v2 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c9 --"wikibase:language"--> c11 v3 --"rdfs:label"--> v4 v1 --"rdfs:label"--> v5 v2 --"rdfs:label"--> v6 end bind5[/"?occupation"/] v1 --o bind5 bind5 --as--o v7 bind6[/"?occupationLabel"/] v5 --o bind6 bind6 --as--o v8 bind7[/"?movementLabel"/] v6 --o bind7 bind7 --as--o v9