I have a table 'wordstyped' containing 'idBook', 'guidUser', 'bookmarkLetter', 'letter' and 'attemptWrong'.
idBook guidUser bookmarkLetter letter attemptWrong
------------------------------------------------------
1 1 100 a 2
1 1 100 a 3
1 1 101 b 6
2 2 101 b 2
2 2 101 b 3
2 2 152 d 7
3 3 153 e 2
I want to select all the record with all their fields containing the max number of 'attemptWrong', but distinct triplets 'idBook', 'guidUser' and 'bookmarkLetter'. I thought I could reach this result with correct use of GROUP BY and MAX operators. The desired result is:
idBook guidUser bookmarkLetter letter attemptWrong
------------------------------------------------------
1 1 100 a 3
1 1 101 b 6
2 2 101 b 3
2 2 152 d 7
3 3 153 e 2
I can get the max attempt right with this query
SELECT *,MAX(attemptWrong) as maxAttemptWrong FROM wordstyped GROUP BY idBook, guidUser, bookmarkLetter
but it returns
idBook guidUser bookmarkLetter letter attemptWrong maxAttemptWrong
-----------------------------------------------------------------------
1 1 100 a 2 3
1 1 101 b 6 6
2 2 101 b 2 3
2 2 152 d 7 7
3 3 153 e 2 2
like in this fiddle http://sqlfiddle.com/#!9/135cf9/1
So it returns the correct maxAttemptWrong, but not the correct record. What am i missing?