I have to select the most common values in the columns of a table, and output it in a table, but I don't know how to do it (in a single query)
here is my table 'stats':
Page | Referrer | Useragent
__________________________
bla | bla bla | bla bla
My code:
echo "<table><tr><td>page</td><td>referrer</td><td>useragent</td></tr>";
$stmt = $db-prepare("SELECT `page`, COUNT(`page`) AS FREQ FROM `stats` GROUP BY `page` ORDER BY FREQ DESC LIMIT 1");
$stmt->execute();
$result = $stmt->fetch();
echo "<tr><td>{$result['page']}</td>";
// and so on with the other two columns
Is there a best way to do it?
And if the query returns two values? (there are two values in the column that appears exactly the same time, and both are the most frequent)