I have a table of quarterback statistics. Each row in the table represents one QB’s performance in one game. The unique ID for each row is called gameId and is composed of the player’s ID plus the game date.
What I want to do is use a select statement to generate a list of all unique quarterbacks in the table, who have thrown at least one completion.
I’m trying to do that with this statement:
SELECT * FROM swdata
WHERE gameComp > 0 AND gameId IN (
SELECT MAX(gameId) FROM swdata GROUP BY playerId)
ORDER BY playerLastName
The first clause is gameComp > 0, and the second clause is to winnow the list down to unique quarterbacks.
What I want to happen is for the first clause to be run, and then for the second clause to be run on the results of the first clause.
But what’s actually happening is that they run concurrently, and this results in some players being omitted from the results.
So, I know I’ve structured it wrong. Can anyone help me get it right?
If you want unique playerIds, wouldn’t the following work?
If you want more than one column, then join back to the original table, with a query such as:
This is in response to your question about
distinct. The distinct returns the distinct values of everything in the select clause. So, the following are equivalent:and
Both of these return all unique combinations of the three columns that appear in the data.