title: Get 3 highest values from table
body: <p>I'd like to count the first 3 users who has the most attributed lines.</p>
  
  <p>SQL Table:</p>
  
  <pre><code>ID | IdUser |  Type   |
  -----------------------
  0  |    1   |  like   |
  1  |    1   |  like   |
  2  |    4   | dislike |
  3  |    5   | dislike |
  4  |    1   |  like   |
  5  |    4   |  like   |
  6  |    5   |  like   |
  8  |    4   |  like   |
  9  |    4   |  like   |
  10 |    3   |  like   |
  11 |    5   |  like   |
  12 |    9   |  like   |
  </code></pre>
  
  <p>Result should be:</p>
  
  <pre><code>idUser[1] with 3 times "like" and 0 "dislike" (3-0 = 3 points)
  idUser[4] with 3 times "like" and 1 "dislike" (3-1 = 2 points)
  idUser[5] with 2 times "like" and 1 "dislikes (2-1 = 1 point )
  </code></pre>
  
  <p>So what I'm trying to do is getting idUser 1 (3 points), then idUser4 (2 points) and finally idUser 5 (1 point) with their points.</p>
  
  <p>I've tried different ways but none have worked.</p>
  
  <p>Here I've tried to create a two-dimensional array with all data and then get the highest values but I couldn't do the second part.</p>
  
  <p>Table 'users' has all users of the website
  table 'points' has likes and dislikes recorded</p>
  
  <pre><code>$sqlUsers = "SELECT * FROM users";
  $resultUsers = $conn-&gt;query($sqlUsers);
  
  $recordsArray = array(); //create array
  
  while($rowUsers = $resultUsers-&gt;fetch_assoc()) {
  
      $idUser = $rowUsers['id'];
  
      //COUNT LIKES OF THE USER
      $sqlLikes = "SELECT COUNT(id) AS numberLikes FROM points WHERE idCibledUser='$idUser' AND type='like'";
      $resultLikes = $conn-&gt;query($sqlLikes);
      $rowLikes = $resultLikes-&gt;fetch_assoc();
  
      //COUNT DISLIKES OF THE USER
      $sqlDislikes = "SELECT COUNT(id) AS numberDislikes FROM points WHERE idCibledUser='$idUser' AND type='dislike'";
      $resultDislikes = $conn-&gt;query($sqlDislikes);
      $rowDislikes = $resultDislikes-&gt;fetch_assoc();
  
      //GET POINTS BY SUBTRACTING DISLIKES FROM LIKES
      $points = $rowLikes['numberLikes'] - $rowDislikes['numberDislikes'];
  
      $recordsArray[] = array($idUser =&gt; $points);
  
  }
  </code></pre>