What are some potential performance pitfalls when using nested sub-selects in PHP MySQL queries?

Using nested sub-selects in MySQL queries can lead to performance issues due to the increased complexity and overhead of executing multiple queries within each other. To improve performance, it is recommended to rewrite the query using JOINs or other methods to reduce the number of sub-selects.

// Example of rewriting a nested sub-select query using JOINs
$query = "SELECT column1, column2 
          FROM table1 
          JOIN table2 ON table1.id = table2.table1_id 
          WHERE table2.column3 = 'value'";
$result = mysqli_query($connection, $query);

if(mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        // Process the data
    }
} else {
    echo "No results found.";
}