What are the benefits of using the DISTINCT keyword in a MySQL query to eliminate duplicate entries in PHP?

When querying a MySQL database in PHP, it is common to encounter duplicate entries in the result set. To eliminate these duplicates and retrieve only unique records, the DISTINCT keyword can be used in the SQL query. This keyword filters out duplicate values from the result set, ensuring that each record is distinct.

// Connect to the database
$mysqli = new mysqli('localhost', 'username', 'password', 'database');

// Query to retrieve unique records using DISTINCT keyword
$query = "SELECT DISTINCT column_name FROM table_name";

// Execute the query
$result = $mysqli->query($query);

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

// Close the connection
$mysqli->close();