sparqlwikidatawikidata-api

Wikidata SPARQL query that returns date a particular property was last edited on queried items


Let's say I'm looking for Wikidata cats who have their place of birth (P19) listed, using this query (also at https://w.wiki/5mdp):

SELECT ?item ?itemLabel ?placeofbirthLabel ?date
WHERE 
{
  ?item wdt:P31 wd:Q146;
        wdt:P19 ?placeofbirth;
        schema:dateModified ?date.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

This retrieves: item id, item label, (the label of) the place of birth, and the date that any part of the item was last updated.

What if I also want to retrieve the date that the place of birth (P19) was last edited?

Thanks in advance!


Solution

  • Place items can also have a schema:dateModified property:

    SELECT ?item ?itemLabel ?item_modified ?placeofbirthLabel ?placeofbirth_modified
    WHERE 
    {
      
      ?item wdt:P31 wd:Q146 ;
            wdt:P19 ?placeofbirth ;
            schema:dateModified ?item_modified .
      
      ?placeofbirth schema:dateModified ?placeofbirth_modified .
      
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
      
    } LIMIT 10