title: Select the maximum value from a table with inner join
body: <p>I have 3 tables; users, tests, and results.</p>
  <p>I made a query which will take all the answers from the tests done by the users.</p>
  <p>When the users does the test multiple times it, the correct answer is saved in a new row.</p>
  <p>For example, when a user does 1 test five times, the correct answers are saved in table but they are treated like 5 individual test.</p>
  <p>So, if I have a number of test of 150, if a user does only 100 different tests, and 1 test 10 times, in the progress bar it will show 110 tests done so far out of the 150 test available, instead of 101 out of 150.</p>
  <p>This is the SQL I used for this:</p>
  <pre><code>SELECT id_test
       , titlu
       , capitol
       , materii_bac.materie
       , teste_bac.intrebari
       , corecte
       , utilizatori.id
       , COUNT(*) AS rez
    FROM 
       (
        (
         ( rezultate_bac 
      JOIN teste_bac 
        ON rezultate_bac.id_test = teste_bac.id
         )
      JOIN materii_bac
        ON teste_bac.materie = materii_bac.id
        )  
     JOIN utilizatori  
       ON rezultate_bac.id_utilizator = utilizatori.id
       ) 
   WHERE utilizatori.id = '$user' 
   GROUP 
      BY id_test 
   ORDER 
      BY rez DESC
  </code></pre>
  <p>Thank you !</p>