如何在两个相关的PHP MySQL查询中订购?

I am creating a dropdown select form based on the results from two cross-referenced MySQL queries, however I cannot get the list to order by alphabet correctly.

I am taking an ID number from the first table "list1", but then need to get its name from the second table "list2", and display them alphabetically.

I tried the ORDER BY, but it does not make sense in either query really.

    <select name="select">
        <?php
        $sql       = "SELECT DISTINCT id FROM list1"; 
        $query     = mysqli_query($connection, $sql) or die (mysqli_error()); 

        while ($row= mysqli_fetch_array($query)) { 
            $id        = $row["id"];
            // *** get the ID name from second table ***
            $sql2 = "SELECT * FROM list2 WHERE id='$id' ORDER BY name ASC LIMIT 1"; 
            $query2 = mysqli_query($connection, $sql2) or die (mysqli_error()); 

            while ($row2 = mysqli_fetch_array($query2)) { 
                $name = $row2["name"];
                echo '<option value="'.$id.'">'.$name.'</option>';
            } // end while

            // *** end get name ***

        } // end while
        ?>
    </select>

Just combine the two queries into one:

select col1, col2 etc
from list2 where list2.id in (SELECT DISTINCT id FROM list1)
order by name asc

This gives you the same list you would have gotten to using your queries and subsequent sub-queries but does it one go and you can order the whole result as needed.

<select name="select">
<?php
  $sql2 = "    select col1, col2 etc
    from list2 where list2.id in (SELECT DISTINCT id FROM list1)
    order by name asc
"; 
  $query2 = mysqli_query($connection, $sql2) or die (mysqli_error()); 
  while ($row2 = mysqli_fetch_array($query2)) { 
  $name = $row2["name"];
  echo '<option value="'.$id.'">'.$name.'</option>';
  } // end while
?>
</select>

Just note that you should probably not use select * when joining tables like this. Just pick the columns you want.