'Concatenate one column over a resultset like kind of group_concat
I am currently writing on a SPARQL query (GraphDB) and try to concatenate the results of one column to avoid the kind of "duplicates".
My current query looks like this
SELECT ?label ?otaupdater
WHERE {
?charger rdf:type mymodel:SoftwarePackage.
?charger mymodel:isCompatibleWith ?target.
?target car:CarId <93718293>.
?charger rdfs:label ?label.
?otaupdater rdf:type mymodel:OTAUpdater.
?charger mymodel:isCompatibleWith ?otaupdater.
}
which gives me a resultset like
| label | otaupdater |
|---|---|
| Chargie_One | 123 |
| Chargie_One | 456 |
| Chargie_Two | 123 |
I tried to work in the command group_concat but only got so far that I ended up with
SELECT (group_concat(?otaupdater; separator=", ") AS ?otaupdaters) where { ... }
but this only returns all otaupdaters in one builded list.
What I am trying to achieve is something like this:
| label | otaupdaters |
|---|---|
| Chargie_One | 123, 456 |
| Chargie_Two | 123 |
Solution 1:[1]
The comment of @UninformedUser lead to the answer:
SELECT ?charger ?label ?target (group_concat(?otaupdater; separator=", ") AS ?otaupdaters)
WHERE {
?charger rdf:type mymodel:SoftwarePackage.
?charger mymodel:isCompatibleWith ?target.
?target car:CarId <93718293>.
?charger rdfs:label ?label.
?otaupdater rdf:type mymodel:OTAUpdater.
?charger mymodel:isCompatibleWith ?otaupdater.
}
GROUP BY ?charger ?label ?target
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Larry |
