query-f6f66e40618bf805b25607312a5ffb69
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
- 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 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