混合两个互连的表

I have

$sql = "SELECT * FROM `address` WHERE ...some requirements...";

Among the results $sql has a column called addressid.

Then I iterate through all addressid and execute

$sql2 = "SELECT * FROM `products` WHERE ...some other requirements... AND addressid = $currentaddressid";

I choose * because I use several columns of each so this needs to be taken into account. The result is like

$valueone = $sql_assoc_array['name'];
$valuetwo = $sql2_assoc_array['nameproduct'];

It looks currently like this:

execute $sql
while ($sql is being fetched)
{
  execute $sql2 with addressid
  while ($sql2 is being fetched)
  {
    do stuff
  }
}

How can I mix both into one command and give the processing necessary to mysql so the results of $sql2 come immediately?

Use inner join between address id of both the tables.

SELECT * from table1 a inner join table2 b where a.addressid=b.addressid.