What are the potential pitfalls of using MySQL "GROUP BY" when calculating total values for each item within a group?

When using MySQL "GROUP BY" to calculate total values for each item within a group, the potential pitfall is that the total values may not be accurate if there are multiple rows with the same item in the group. To solve this issue, you can use the "SUM" function along with "GROUP BY" to calculate the total values for each item within the group accurately.

$query = "SELECT item, SUM(value) AS total_value FROM table_name GROUP BY item";
$result = mysqli_query($connection, $query);

if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        echo "Item: " . $row['item'] . ", Total Value: " . $row['total_value'] . "<br>";
    }
} else {
    echo "No results found.";
}