How can the WHERE clause be utilized effectively in SQL queries in PHP to filter results and avoid duplicate entries?

When using the WHERE clause in SQL queries in PHP, you can filter results based on specific conditions to avoid duplicate entries. By specifying the criteria in the WHERE clause, you can narrow down the results to only include the records that meet the specified conditions. This helps in retrieving accurate and relevant data from the database without duplicates.

<?php
// Establish a connection to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// SQL query with WHERE clause to filter results and avoid duplicates
$sql = "SELECT * FROM table_name WHERE condition_column = 'condition_value'";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data of each row
    while($row = $result->fetch_assoc()) {
        echo "Column1: " . $row["column1"]. " - Column2: " . $row["column2"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>