1

I'm learning SPARQL for Wikidata queries, and I'm trying to figure out how to query coaches that have worked at one point for two sport teams.

I've achieved how to query the ones that worked for only one team:

SELECT ?coach ?coachLabel
WHERE {
  wd:Q7156 p:P286 ?team1.
  ?team1 ps:P286 ?coach.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}
}

but I don't know how to intersect it with the results for a ?team2.

How can I solve this?

starball
  • 20,030
  • 7
  • 43
  • 238
  • Does this answer your question? [Using SPARQL to locate a subject with multiple occurrences of same property](https://stackoverflow.com/questions/18919742/using-sparql-to-locate-a-subject-with-multiple-occurrences-of-same-property) – Marijn Apr 23 '23 at 10:12
  • the main issue is that your variable names are a bit misleading. You should not call it `team1` if it denotes a Wikidata statement node about the coach itself. Regarding your question, just reuse the `coach` variable, and make the club 1 and club 2 variables with a filter that forces them being different. – UninformedUser Apr 23 '23 at 10:42
  • By the way, is there any real world example where coach works for 2 teams at the same time? If not, it's hard to validate the query – UninformedUser Apr 23 '23 at 10:42
  • you can start with `SELECT ?team1 ?team1Label ?team2 ?team2Label ?coach ?coachLabel WHERE { ?team1 p:P286 ?team1_stmt. ?team1_stmt ps:P286 ?coach. ?team2 p:P286 ?team2_stmt. ?team2_stmt ps:P286 ?coach. FILTER(?team1 != ?team2) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".} } LIMIT 10` - now all you have to do is to capture the "same time" restriction by filtering on the statement qualifiers. – UninformedUser Apr 23 '23 at 10:45

0 Answers0