简体   繁体   中英

Group Concat using sparql query

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM