query-0c406166c7aa7be41c2cc9435b61b5bf
Prevent Duplication with Multiple GROUP_CONCAT PropertiesHello! I'm working on a query for data on people with University of Virginia as an employer:
Use at
- https://query.wikidata.org/sparql
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#>
SELECT
?person ?personLabel ?sexorgender (GROUP_CONCAT(?ethnicityLabel;SEPARATOR=', ') AS ?ethnicity)
?birthplace (GROUP_CONCAT(?citizenshipLabel;SEPARATOR=', ') AS ?citizenship) ?religion
?sexuality
WHERE
{
?person wdt:P108 wd:Q213439 .
?person rdfs:label ?personLabel . FILTER(LANG(?personLabel)='en')
OPTIONAL { ?person wdt:P21 ?value .
?value rdfs:label ?sexorgender . FILTER(LANG(?sexorgender)='en') }
OPTIONAL { ?person wdt:P172 ?ethnicity .
?ethnicity rdfs:label ?ethnicityLabel . FILTER(LANG(?ethnicityLabel)='en') }
OPTIONAL { ?person wdt:P19 ?value2 .
?value2 rdfs:label ?birthplace . FILTER(LANG(?birthplace)='en') }
OPTIONAL { ?person wdt:P27 ?citizenship .
?citizenship rdfs:label ?citizenshipLabel . FILTER(LANG(?citizenshipLabel)='en') }
OPTIONAL { ?person wdt:P140 ?value3 .
?value3 rdfs:label ?religion . FILTER(LANG(?religion)='en') }
OPTIONAL { ?person wdt:P91 ?value4 .
?value4 rdfs:label ?sexuality . FILTER(LANG(?sexuality)='en') }
}
GROUP BY ?person ?personLabel ?sexorgender ?birthplace ?religion ?sexuality
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?birthplace"):::projected
v15("?citizenship")
v3("?citizenshipLabel"):::projected
v15("?ethnicity")
v5("?ethnicityLabel"):::projected
v8("?person"):::projected
v6("?personLabel"):::projected
v2("?religion"):::projected
v7("?sexorgender"):::projected
v1("?sexuality"):::projected
v9("?value")
v11("?value2")
v13("?value3")
v14("?value4")
c3(["wd:Q213439"]):::iri
f0[["?personLabel = 'en'"]]
f0 --> v6
v8 --"wdt:P108"--> c3
v8 --"rdfs:label"--> v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v8 -."wdt:P21".-> v9
v9 --"rdfs:label"--> v7
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v8 -."wdt:P172".-> v15
v15 --"rdfs:label"--> v5
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v8 -."wdt:P19".-> v11
v11 --"rdfs:label"--> v4
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v8 -."wdt:P27".-> v15
v15 --"rdfs:label"--> v3
end
subgraph optional4["(optional)"]
style optional4 fill:#bbf,stroke-dasharray: 5 5;
v8 -."wdt:P140".-> v13
v13 --"rdfs:label"--> v2
end
subgraph optional5["(optional)"]
style optional5 fill:#bbf,stroke-dasharray: 5 5;
v8 -."wdt:P91".-> v14
v14 --"rdfs:label"--> v1
end
bind3[/"?ethnicityLabel"/]
v5 --o bind3
bind3 --as--o v15
bind4[/"?citizenshipLabel"/]
v3 --o bind4
bind4 --as--o v15