Search code examples
sparqlwikidata

Select footballers from two or more countries with SPARQL wikidata query


I'm trying to get the day of birth of all the footballers on wikipedia per country. Until now I've managed to get all the ones for one country, but I would like to get the ones on many countries at the same time, something like:

SELECT ?person ?dateOfBirth
WHERE {
  ?person wdt:P1532 wd:Q16 OR ?person wdt:P1532 wd:Q141;
  wdt:P569 ?dateOfBirth.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Q16 is canada and Q141 is Argentina

Thanks!


Solution

  • To not limit your query to a single country, replace wd:Q16 by a variable, i.e. ?person wdt:P1531 ?country.

    Then you need to restrict your query to football players. This can be done with the following line

    ?person wdt:P106 wd:Q937857.
    

    And probably you want the names of the players, not only der ID. Thus, add ?personLabel after "select".

    Combined, the query reads

    SELECT ?person ?personLabel ?country ?countryLabel ?dateOfBirth
    WHERE {
      ?person wdt:P106 wd:Q937857;
              wdt:P1532 ?country;          
              wdt:P569 ?dateOfBirth.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }  
    }