I want to count all duplicates and output them as a number.
database:
user
Sam
Sam
Tom
Tom
Tom
John
and here is my code:
$sql = "select user, count(*) duplicates from users group by user order by duplicates desc";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["user"]. "<br>";
}
} else {
}
well this works but here is the output:
Tom
Sam
John
i want the output to be only numbers:
3
2
1
Thanks for answering.
select count(*) duplicates from users group by user order by duplicates desc?