I need to get the most registered name from a database, based on count().
I have a table in the database that has these columns and data
id | name | code
1 Craig 4567
2 John 4567
3 Liam 4568
4 sam 4569
5 sam 4569
and what I need to do is count the name field so that which ever name appears most will be displayed. In this case its Sam.
I have tried:
$ck_af = $wpdb->get_results(
$wpdb->prepare("SELECT * FROM wp_code_log ORDER BY CONVERT(COUNT(name), UNSIGNED INTEGER) DESC LIMIT 1")
);
can anyone see what is happening?
It is ouputting Craig.
I need it to output which ever name is most stored and also the code afterwards, so it should be:
sam : 4569