0

I have the following working query with the aim of showing all subclasses of Q3314483 [1]:

SELECT ?item (SAMPLE(?itemLabel) AS ?itemLabel) (SAMPLE(?subclass) as ?subklass) (SAMPLE(?subclassLabel) AS ?subLabel) WHERE {
   ?item wdt:P279* wd:Q3314483 ;
         wdt:P279 ?subclass .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
group by ?item

The SAMPLE and GROUP pattern is designed to make the items unique. It seems to work, however the label columns are blank. How can they be displayed?

  1. Based on this
mahemoff
  • 44,526
  • 36
  • 160
  • 222
  • https://w.wiki/8gn, https://w.wiki/8go – Stanislav Kralin Sep 21 '19 at 12:32
  • That works (assuming labels are unique by ID), but omits the 3rd and 4th columns – mahemoff Sep 21 '19 at 13:47
  • 1
    `SELECT ?item (SAMPLE(?itemLabel) AS ?itemLabel) (SAMPLE(?subclass) as ?subklass) (SAMPLE(?subclassLabel) AS ?subLabel) WHERE { ?item wdt:P279* wd:Q3314483 ; wdt:P279 ?subclass . SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". ?subclass rdfs:label ?subclassLabel. ?item rdfs:label ?itemLabel.} } group by ?item` – UninformedUser Sep 21 '19 at 14:00
  • @AKSW That's the winner! Can you transfer it to an answer so I can accept it? – mahemoff Sep 21 '19 at 14:11

1 Answers1

0

Thanks to @AKSW in the comments. Answer is:

SELECT ?item (SAMPLE(?itemLabel) AS ?itemLabel) (SAMPLE(?subclass) as ?subklass) (SAMPLE(?subclassLabel) AS ?subLabel) WHERE {
  ?item wdt:P279* wd:Q3314483 ;
  wdt:P279 ?subclass . SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". ?subclass rdfs:label ?subclassLabel. ?item rdfs:label ?itemLabel.
  }
}
GROUP BY ?item
mahemoff
  • 44,526
  • 36
  • 160
  • 222