What are the potential pitfalls of using the "GROUP BY" clause in a MySQL query when selecting multiple columns?

When using the "GROUP BY" clause in a MySQL query with multiple columns, it is important to remember that all non-aggregated columns in the SELECT statement must also be included in the "GROUP BY" clause. Failure to do so can result in unpredictable results or errors. To solve this issue, make sure to include all selected columns in the "GROUP BY" clause to ensure accurate grouping of data.

$query = "SELECT column1, column2, COUNT(*) 
          FROM table_name 
          GROUP BY column1, column2";
$result = mysqli_query($connection, $query);

if($result){
    // Process the query result
} else {
    echo "Error: " . mysqli_error($connection);
}