What are the potential issues with joining tables in PHP SQL queries and how can they be resolved?

One potential issue with joining tables in PHP SQL queries is that it can lead to duplicate results if the join conditions are not properly specified. This can be resolved by using DISTINCT keyword in the SELECT statement to eliminate duplicates.

$query = "SELECT DISTINCT column_name FROM table1 JOIN table2 ON table1.id = table2.id";
$result = mysqli_query($connection, $query);

if(mysqli_num_rows($result) > 0){
    while($row = mysqli_fetch_assoc($result)){
        echo $row['column_name'] . "<br>";
    }
} else {
    echo "No results found";
}