Is there a way that I can do an MySQL query and find only one record per year?
I need to confirm that there is at least one game for a baseball team for a particular year.
Right now I am having to find all the games for all the years, then use array_unique to strip out the duplicate years.
For example, the teams below would have the following records.
Team A: 40 games + 42 games + 38 games equals 120 games
Team B: 42 games + 43 games equals 85 games
Team C: 38 games + 40 games equals 78 games
(Note: I had to use Html <pre> tag to get my columns to line up)
<pre>
Games Per Season
2012 2013 2014
Team A 40 42 38
Team B 0 42 43
Team C 38 40 0
</pre>
I can do a query for Team A and find all the years for which Team A had games. That returns 120 games. Then use array_unique() to strip out the duplicate years. The years array for Team A will then have three elements. The years array would look like: array(0=>2012, 1=>2013,2=>2014)
I can do a query for Team B and find all the years for which Team B had games. That returns 85 games. Then use array_unique() to strip out the duplicate years. The years array for Team A will then have just two elements (since there are games for only two years). The years array for Team B would look like: array(0=>2013, 1=>2014)
I can do a query for Team C and find all the years for which Team C had games. That returns 78 games. Then use array_unique() to strip out the duplicate years. The years array for Team C will then also have just two elements (since there are games for only two years). The years array for Team C would look like: array(0=>2012, 1=>2013)