Abdul Muqeet
Abdul Muqeet

Reputation: 75

Sparql Query for wikidata to get multiple values from property

I am trying to create a wiki data SPARQL query. What I want to do is to get multiple items from the some property For example: I am trying to fetch all data that have property of instance of statistical packages. But the problem I am facing is for example a Statistical Package of Social Sciences have property type 348 which have multiple versions. I wanted to fetch all these version and also the publication date if the version have publication date as well. I read some document and try to create a query but I am unable to get all version from the property p:348.

SELECT ?software ?softwareLabel ?developerLabel ?versionLabel ?date
WHERE
{
  ?software wdt:P31 wd:Q13199995 . 
   OPTIONAL { ?software wdt:P178 ?developer. }
  OPTIONAL { ?software  wdt:P348 ?version. }
   OPTIONAL { 
  FILTER EXISTS {
       ?software wdt:P348 ?version2. 
      FILTER ( ?version != ?version2 )
      }
     }

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}

Here I have attached the query that I am using to get all the required information. I am really stuck on this problem. I would be really grateful for any kind of help.

Upvotes: 1

Views: 1138

Answers (1)

Matthias Winkelmann
Matthias Winkelmann

Reputation: 16394

either UNION or VALUES is your friend:

SELECT ?software ?softwareLabel ?developerLabel
    ?versionLabel ?date WHERE {   VALUES ?type 
    {wd:Q7397 wd:Q13199995 wd:Q166142}   ?software wdt:P31 ?type   
    OPTIONAL { ?software wdt:P178 ?developer. }  
    OPTIONAL {     ?software p:P348 ?stmt.    
    ?stmt ps:P348 ?version.     
    OPTIONAL { ?stmt pq:P577 ?date. }   }   
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". } }

Upvotes: 3

Related Questions