Query Library

Casey Trauer submitted this query on: August 12, 2009 11:09am EDT
TITLE Get all plays for a batter in an MLB game
SPORTS Baseball
QUERY SELECT dn_player.first_name, dn_player.last_name, p.person_key, bas.*, bap.*

FROM baseball_event_states bas
JOIN baseball_action_plays bap ON bas.id = bap.baseball_event_state_id
JOIN events e ON bas.event_id = e.id
JOIN persons p ON bas.batter_id = p.id
JOIN display_names dn_player ON bas.batter_id = dn_player.entity_id

WHERE dn_player.entity_type = 'persons'
AND e.event_key = 'l.mlb.com-2009-e.26017'
AND p.person_key = 'l.mlb.com-p.4406'
AND bas.context = 'event-play';
DESCRIPTION This query applies only to play-by-play boxscores. It will return a wide array of data for an at-bat, including the game state at the time of the at-bat and the result of the at-bat.
DBs TESTED MySQL
ADDITIONAL NOTES Please note that for TSN play by play data, this query will also return events not involving the batter listed. For example, if there was a stolen base or a pickoff when the player is at bat, those events will be returned in this query. So if you do not want this information returned, you will have to filter out all these non-hitting events. For a vocab list of play-types, please consult the SportsML documentation.