What are the potential pitfalls of using GROUP BY to filter out duplicates in a single column query?
Using GROUP BY to filter out duplicates in a single column query can lead to unexpected results if there are multiple columns in the SELECT statement. This is because GROUP BY will group by all columns, not just the specified one. To solve this issue, you can use the DISTINCT keyword in the SELECT statement to explicitly filter out duplicates in a single column query.
$query = "SELECT DISTINCT column_name FROM table_name";
$result = mysqli_query($connection, $query);
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
// Process the results
}
}