Reputation: 11
Can some one help me how to use group_concat in sparql query. When i am using in the database it is pulling out iri from the data. How to pull the the labels for the objects present in the database using group_concat.
Upvotes: 0
Views: 295
Reputation: 1966
You will usually have IRIs with a label. Now, to return labels only, a query like this will work:
SELECT ?item ?label
WHERE {
?item rdfs:label ?label
}
Note that rdfs:label
is conventionally used for labels, but any name can be used - it depends on the data that you have.
Now, imagine we want to find a GROUP_CONCAT
of children's names, grouped by mother.
First, the query for the children and labels looks like this:
SELECT ?mother ?child ?label
WHERE {
?mother :hasChild ?child .
?child rdfs:label ?label .
}
Notice that ?mother
and ?child
will be bound to IRIs here, and ?label
to a string.
Now for the GROUP_CONCAT
, you will just need a query like:
SELECT ?mother (GROUP_CONCAT(?label; SEPARATOR=", ") AS ?concat)
WHERE {
?mother :hasChild ?child .
?child rdfs:label ?label .
}
GROUP BY ?mother
Upvotes: 0