Q:

How to combine GROUP BY and MAX in mysql to get the full record with the max value of a field? 

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? 

A:

I believe you will need some sort of subquery to do this, even if you were using analytic functions.   Using a pre MySQL 8 approach, we can join your wordstyped table to a subquery which finds the max wrong attempts for each bookmark letter.   This restricts the original table to only the matching rows which you want in your final output. 
SELECT w1.* 
FROM wordstyped w1
INNER JOIN
(
    SELECT bookmarkLetter, guidUser, MAX(attemptWrong) AS maxAttemptWrong
    FROM wordstyped
    GROUP BY bookmarkLetter, guidUser
) w2
    ON w1.bookmarkLetter = w2.bookmarkLetter AND
       w1.guidUser = w2.guidUser AND
       w1.attemptWrong = w2.maxAttemptWrong;

