I am doing a sparql query on the data from the Lahman baseball database. Here's some sample data to showcase what my query needs to do.
@prefix ma: <http://mydataset.com/ns/master#> .
ma:billybo01 ma:nameFirst "Billy" .
ma:billybo01 ma:nameLast "Bored" .
ma:chrisgow01 ma:nameFirst "Chris" .
ma:chrisgow01 ma:nameLast "Gowan" .
ma:bradlee01 ma:nameFirst "Brad" .
ma:bradlee01 ma:nameLast "Lee" .
@prefix teamQ2: <http://mydataset.com/ns/teamQ2#> .
@prefix yearQ2: <http://mydataset.com/ns/yearQ2#> .
@prefix ma: <http://mydataset.com/ns/master#> .
teamQ2:BS1 yearQ2:1871 ma:billybo01 .
teamQ2:BS1 yearQ2:1872 ma:billybo01 .
teamQ2:BS1 yearQ2:1873 ma:billybo01 .
teamQ2:LAN yearQ2:1874 ma:billybo01 .
teamQ2:LAN yearQ2:1871 ma:chrisgow01 .
teamQ2:LAN yearQ2:1872 ma:chrisgow01 .
teamQ2:BS1 yearQ2:1871 ma:bradlee01 .
teamQ2:BS1 yearQ2:1872 ma:bradlee01 .
I am trying to get all first and last names of players who only played for the team LAN and no other team. My attempt is what I show below. I was hoping to query for all players who were on the team LAN in any year, get their masterID, then subtract all players from that set that ever appeared on a team other than LAN. Then I just match up the masterId with the first and last name at the end. Right now it is returning the data as if the MINUS
and FILTER !EXISTS
cancel each other out and it just returns all players who played on LAN. Is there something else I need to use other than MINUS
or the FILTER !EXISTS
?
PREFIX ma: <http://mydataset.com/ns/master#>
PREFIX teamQ2: <http://mydataset.com/ns/teamQ2#>
SELECT DISTINCT ?nameFirst ?nameLast
WHERE
{
teamQ2:LAN ?yearID ?masterID .
MINUS{FILTER (
!EXISTS {
teamQ2:LAN ?yearID ?nonLANmasterID .
}
)}
?masterID ma:nameLast ?nameLast .
?masterID ma:nameFirst ?nameFirst .
}
ORDER BY ?nameLast ?nameFirst