How can Aggregatfunktionen in SQL be used to avoid duplicate entries when fetching data in PHP?

Aggregatfunktionen in SQL can be used to avoid duplicate entries when fetching data in PHP by using functions like COUNT(), SUM(), AVG(), etc. These functions can be used to group and aggregate data, eliminating the need to manually filter out duplicates in PHP code. By utilizing these functions in the SQL query, we can ensure that only unique and aggregated data is returned to PHP for processing.

<?php
// Connect to database
$connection = new mysqli("localhost", "username", "password", "database");

// Query to fetch unique data using COUNT() function
$query = "SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name";

// Execute query
$result = $connection->query($query);

// Fetch and display results
while ($row = $result->fetch_assoc()) {
    echo $row['column_name'] . ": " . $row['COUNT(*)'] . "<br>";
}

// Close connection
$connection->close();
?>