What are the potential issues with using COUNT() in a MySQL query with LEFT JOIN in PHP?

When using COUNT() in a MySQL query with LEFT JOIN in PHP, the potential issue is that it may return incorrect results due to counting rows from the joined table. To solve this issue, you can use COUNT(DISTINCT column_name) to count only unique values from the specified column in the joined table.

$query = "SELECT t1.id, COUNT(DISTINCT t2.column_name) AS count_column
          FROM table1 t1
          LEFT JOIN table2 t2 ON t1.id = t2.id
          GROUP BY t1.id";
$result = mysqli_query($connection, $query);

while ($row = mysqli_fetch_assoc($result)) {
    echo "ID: " . $row['id'] . " | Count: " . $row['count_column'] . "<br>";
}