Topic on Talk:Wikidata Query Service

SELECT DISTINCT returns duplicates

4
Tena inmotion (talkcontribs)

The following query returns duplicate rows:

SELECT DISTINCT ?s ?l

WHERE {

        ?s wdt:P31 wd:Q19829914 ;

            rdfs:label ?l .

        FILTER(langMatches(lang(?l), "en"))

}

Fnielsen (talkcontribs)

I am not familiar with "langMatches". Is there an error? This seems to be working:

SELECT DISTINCT ?property ?label
WHERE {
  ?property wdt:P31 wd:Q19829914 ;
            rdfs:label ?label .
  FILTER(LANG(?label) = "en")
}
Tena inmotion (talkcontribs)

Thanks, that seems to solve it.

TomT0m (talkcontribs)

In the original query you select all languages variants.

LangMatches will match american english and UK-english variants, who are both present in Wikidata sometimes, with "en". And are technically different labels values as far as sparql is concerned because of the different language tag.

So you end-up having duplicates. To remove them you might remove the language tag with something like replacing "?l" with "(str(?l) as ?label)"

Reply to "SELECT DISTINCT returns duplicates"