Im trying to join 3 tables together using inner joins, but the results are showing more records than what should be there. My Data tables are set up like this:
Table:gameday.atbats GameName Inning num b s o Batter Pitcher Result ----------------------------------------------------------------------------------------- gid_2008_09_24_cinmlb_houmlb_1 1 1 2 3 1 457803 150116 Jay Bruce strikes out swinging. gid_2008_09_24_cinmlb_houmlb_1 1 2 1 0 2 433898 150116 Jeff Keppinger lines out to right fielder Hunter Pence. gid_2008_09_24_cinmlb_houmlb_1 1 3 3 1 2 458015 150116 Joey Votto singles on a line drive to right fielder Hunter Pence. gid_2008_09_24_cinmlb_houmlb_1 1 4 2 3 3 429665 150116 Edwin Encarnacion called out on strikes. gid_2008_09_24_cinmlb_houmlb_1 1 5 1 2 0 430565 459371 Kazuo Matsui singles on a line drive to right fielder Jay Bruce. ----------------------------------------------------------------------------------------- Table: Gameday.pitches GameName GameAtBatID Result ------------------------------------------------------ gid_2008_09_24_cinmlb_houmlb_1 1 Called Strike gid_2008_09_24_cinmlb_houmlb_1 1 Ball gid_2008_09_24_cinmlb_houmlb_1 1 Swinging Strike gid_2008_09_24_cinmlb_houmlb_1 1 Ball gid_2008_09_24_cinmlb_houmlb_1 1 Foul gid_2008_09_24_cinmlb_houmlb_1 1 Foul gid_2008_09_24_cinmlb_houmlb_1 1 Swinging Strike gid_2008_09_24_cinmlb_houmlb_1 2 Ball gid_2008_09_24_cinmlb_houmlb_1 2 In play, out(s) gid_2008_09_24_cinmlb_houmlb_1 3 Called Strike gid_2008_09_24_cinmlb_houmlb_1 3 Ball -------------------------------------------------------- Table:batters GameName id name_display_first_last ---------------------------------------------------------------------------------- gid_2008_09_24_cinmlb_houmlb_1 407783 Geoff Geary gid_2008_09_24_cinmlb_houmlb_1 209315 David Newhan gid_2008_09_24_cinmlb_houmlb_1 115629 LaTroy Hawkins gid_2008_09_24_cinmlb_houmlb_1 113889 Darin Erstad gid_2008_09_24_cinmlb_houmlb_1 457803 Jay Bruce gid_2008_09_24_cinmlb_houmlb_1 433898 Jeff Keppinger gid_2008_09_24_cinmlb_houmlb_1 458015 Joey Votto gid_2008_09_24_cinmlb_houmlb_1 429665 Edwin Encarnacion --------------------------------------------------------------------------- I'm running what seems like a fairly standard set of inner joins, connecting each of the various tables together to get a output that shows me pitch by pitch what each batter did throughout the game. My code is as follows:
SELECT gameday.atbats.inning, gameday.batters.name_display_first_last, gameday.pitches.Result FROM gameday.atbats Inner join gameday.pitches on gameday.atbats.num = gameday.pitches.gameAtBatID inner join gameday.batters on gameday.atbats.batter = gameday.batters.ID where gameday.atbats.gamename = "gid_2008_09_24_cinmlb_houmlb_1" My issue is that when I run this query, batters are having more results than they should. For example, in the first inning Batter jay Bruce (num 1 in the atbats table) should have 7 pitches thrown to him in the first inning, but when I run the query he will have 10 pitches thrown to him. What Am I doing incorrectly to get these results. Also, I am aware that these field names are named horribly, but they were named by someone else, and I have not had a chance to change them yet.