I have been looking to see how I would apply logic in my SQL query to accomplish my goal. I am open to any suggestions at this point.
I have two tables that I have an inner join between. The two tables being a complete listing of all MLB baseball players (past & present), and a table of all of the Hall of Famer players. I am looking to come up with a query result of one unique player per row and have a column filled in with a Y or an N if they are in the Hall of Fame.
Table 1 – Players
ID
HallofFameID
NameFirst
NameLast
Table 2 – HallOfFame
HallofFameID
YearID
Votes
Inducted
Each player has one entry in the Players Table but may have their PlayerID entered multiple times in the Hall of Fame Table. In my resulting query with inner joins will pull up rows that will look like this…
Player ID | NameFirst | NameLast | YearID | Votes | Inducted
001........| Don.........| Sutton......| 1992.....| 100.....| N
001........| Don.........| Sutton......| 1993.....| 89......| N
001........| Don.........| Sutton......| 1994.....| 100.....| N
001........| Don.........| Sutton......| 1998.....| 341.....| Y
002........| Mickey......| Mantle......| 1974.....| 341.....| Y So forth...
I would like my resulting query to not display the rows from 1992-1997 where Don Sutton was not elected, but just display the 1998 year, and then move down to the Mickey Mantle row with a Y. Also there are other players who have not been elected, that have a N next to their names for multiple years of Hall eligibility that I need to display on the same query result.
I have included my working SQL for reference. I am not looking for anyone to write my SQL, but rather point me in the right direction with keywords, or logic that I may be missing.
Thanks in advance
Select DISTINCT
Master.namefirst,
Master.nameLast,
Master.HofID,
HallOfFame.inducted,
HallOfFame.yearid
FROM
HallOfFame
INNER JOIN
Master On HallOfFame.hofID = Master.hofID
Group by
Master.nameFirst,
Master.nameLast,
Master.PlayerID,
Master.hofID,
HallOfFame.inducted,
HallOfFame.yearid*
Try this instead:
SQL Fiddle Demo
This will give you: