There was a need to extract from the database the value that was repeated more times.
I tried different options, but I’m doing something wrong.

Example:
Column with numbers 8 1 2 6 8 5 1 8 - you need to display the number 8.

  • 2
    so what you got? - Jean-Claude
  • I'll try it now - 100ROZE
  • The code of several failed attempts / options should be added to the question. - Regent
  • And if the question is solved by answering below? Do I need to insert the code in the question? - 100ROJ
  • @ 100 NO FAR, then there is no special meaning anymore. The only thing: if you are completely satisfied with the answer to SQL, without PHP (despite some "parsing"), then php and pdo tags should be removed from the question. - Regent

1 answer 1

In this case, they usually resort to counting the number of values ​​using the COUNT() function and then sorting using ORDER BY

 SELECT number FROM tbl GROUP BY number ORDER BY COUNT(*) DESC LIMIT 1 
  • Thank you very much, the question has been resolved as it should, but what should be displayed in PHP? I checked it in SQL, everything is fine, in PHP I made print_r, nothing came out, although it might be my copying - 100ROJE
  • @ 100ROZH, it is better then to ask a new question or use an already prepared answer, for example, an example of output is here ru.stackoverflow.com/questions/231280 - cheops