Use a variable (?foo
) instead of wd:Q42
.
Then you have three options:
- Leave it like that to query all items.
(Not a good idea if the additional triple patterns aren’t restrictive enough.)
- Add triple patterns using the
?variable
to narrow down which items to query.
(Just like you did with ?statement
.)
- Provide a list of subjects that should be queried (using
VALUES
).
Example for querying writers (occuption = Q36180):
SELECT ?writerLabel ?spouseLabel ?starttimeLabel ?endtimeLabel
WHERE {
VALUES ?writer { wd:Q42 wd:Q47087 }
?writer p:P26 ?statement_spouse ;
p:P106 ?statement_occupation .
?statement_occupation ps:P106 wd:Q36180 .
?statement_spouse ps:P26 ?spouse ;
pq:P580 ?starttime ;
pq:P582 ?endtime .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ?starttime
LIMIT 10
By commenting out the VALUES
line, you would query all writers instead of just the two listed.
Note that your query requires an end time. To also find ongoing marriages, you can use OPTIONAL
for that triple pattern:
?statement_spouse ps:P26 ?spouse ;
pq:P580 ?starttime .
OPTIONAL {
?statement_spouse pq:P582 ?endtime .
}