W3C home > Mailing lists > Public > public-sparql-dev@w3.org > April to June 2010

Re: getting multivalued properties in a single query

From: Lee Feigenbaum <lee@thefigtrees.net>
Date: Mon, 28 Jun 2010 09:23:37 -0400
Message-ID: <4C28A259.1020707@thefigtrees.net>
To: Sergio Fernández <sergio.fernandez@fundacionctic.org>
CC: public-sparql-dev@w3.org
On 6/28/2010 8:12 AM, Sergio Fernández wrote:
> Hi,
> I wonder if anyone knows how can I write a single SPARQL query to
> retrieve all triples with the same triple pattern without post-process
> the query result.
> Let's put an example: using FOAF is quite common to have a dataset like:
> #person1 foaf:name "Person1" .
> #person1 foaf:knows #person2 .
> #person1 foaf:knows #person3 .
> ...
> #person1 foaf:knows #personN .
> How can I get all knows for a concrete subject? And I'd like to do it
> just with SPARQL in a single query. So the two ways that I know:
> 1. Post-process the query's result, merging result about the same subject
> 2. Perform two queries: one for the single properties, and a second
> for the multivalued stuff.
> are not valid at all. Anyone has any another idea...?
> Thanks in advance.
> Kind regards,

Hi Sergio,

I think you are saying that you require a single row per subject, but 
want all of the foaf:knows for that subject within that single solution. 
You can't do this in SPARQL 1.0 without post-processing. You will be 
able to do it in SPARQL 1.1 with the GROUP_CONCAT aggregate:

SELECT ?person (GROUP_CONCAT(?knows) AS ?knows_string)
   ?person foaf:knows ?knows
GROUP BY ?person

Received on Monday, 28 June 2010 13:24:17 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:15:50 UTC