F
fix
Hi all,
I am writing a voting system for a committee election.
Here is the table structure:
user (the one who voted)
position
candidate_id
time (time of vote)
Each row records the user name of the one who voted, which candidate for
which position and the time of vote. Everyone has one vote for each
position, but they can vote again if they can their mind - only the last
vote counts.
But to select the last votes per user per position has gotten me into
trouble.
I can do
SELECT [user], [position], MAX([time]) FROM votes GROUP BY [user],
[position]
to select the time of the latest votes, but I cannot get candidate_id of
that vote into the SELECT clause, I'll get an error:
SELECT [user], [position], MAX([time]), candidate_id FROM votes GROUP BY
[user], [position]
So what should I do to get the whole row with the latest time per user per
position.
Thanks.
fix.
--
I am writing a voting system for a committee election.
Here is the table structure:
user (the one who voted)
position
candidate_id
time (time of vote)
Each row records the user name of the one who voted, which candidate for
which position and the time of vote. Everyone has one vote for each
position, but they can vote again if they can their mind - only the last
vote counts.
But to select the last votes per user per position has gotten me into
trouble.
I can do
SELECT [user], [position], MAX([time]) FROM votes GROUP BY [user],
[position]
to select the time of the latest votes, but I cannot get candidate_id of
that vote into the SELECT clause, I'll get an error:
SELECT [user], [position], MAX([time]), candidate_id FROM votes GROUP BY
[user], [position]
So what should I do to get the whole row with the latest time per user per
position.
Thanks.
fix.
--