How can PHP developers ensure that only specific data is retrieved from multiple tables using JOIN statements?

When using JOIN statements to retrieve data from multiple tables in PHP, developers can ensure that only specific data is retrieved by specifying the columns they want in the SELECT statement. By explicitly listing the columns needed, developers can avoid retrieving unnecessary data and improve query performance.

$query = "SELECT table1.column1, table2.column2
          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)){
        // Process retrieved data here
    }
}