You can use GROUP BY to group by a specific column, and then use the SAMPLE() aggregate to select one of the values ββfrom other columns, for example.
PREFIX dbo: <http://dbpedia.org/ontology/> SELECT ?city (SAMPLE(?name) AS ?cityName) (SAMPLE(?pop) AS ?cityPop) WHERE { ?city a dbo:Settlement . ?city foaf:name ?name . ?city dbo:populationTotal ?pop . ?city dbo:country ?country . ?city dbo:country dbpedia:Italy . FILTER (?pop > 100000) } GROUP BY ?city
So, grouping by ?city , you get only one row for each city, since you are grouped by ?city , you cannot directly select variables that are not group variables.
Instead, you should use the SAMPLE() aggregate to select one of the values ββfor each of the non-group variables that you want to have in the final results. This will select one of the ?name and ?pop values ββto return as ?cityName and ?cityPop respectively
source share