-2

My columns are Year and AthleteID. Every time someone registers they keep the same AthleteID, so A query that returns all members from all years would look like the below:

|AthleteID | Year|
| 1234     | 2016|
| 1234     | 2017|
| 3243     | 2016|
| 0134     | 2015|
| 4567     | 2017|
| 5678     | 2017|
| 1234     | 2017|

I want to return just new member in 2017 so in the example above it would return only the below:

|AthleteID|| Year|
| 4567     | 2017|
| 5678     | 2017|
sjw0525
  • 329
  • 2
  • 17
  • 1
    What have you tried? Show your attempt. If it doesn't work, we can try to help. – Eric Oct 11 '17 at 21:17
  • and see [Why should I provide an MCVE for what seems to me to be a very simple SQL query](http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-query) – Strawberry Oct 11 '17 at 22:52
  • Also, you have a duplicate entry, which begs the question: what's your PRIMARY KEY?!?!?! – Strawberry Oct 11 '17 at 22:57

1 Answers1

1

One way to do this is to get the minimum year for each athlete, and then filter the new users with a HAVING clause.

Like so:

SELECT AthleteID,
       min(YEAR)
FROM your_table
GROUP BY AthleteID
HAVING min(YEAR) = 2017
Ike Walker
  • 64,401
  • 14
  • 110
  • 109