结合两个SQL查询成一个PHP

我有两个查询:

$userID = 1;
$sql = "SELECT `ID` FROM `room` WHERE `userID` = ".$userID."";
$statement = $mysqli->prepare($sql);
$statement->execute();
$result = $statement->get_result();

while($row = $result->fetch_object()) { 
   $sql2 = "SELECT room.*, user.firstname AS firstname FROM `room` 
            LEFT JOIN `user` ON room.userID = user.ID
            WHERE `userID` != ".$userID." AND `ID` = ".$row->ID."";
} 

有没有办法将两个查询合并为一个?

评论