Merge 2 SQL statements into 1? Can anyone help me transforming these 2 SQL statements into 1?

$query2 = "SELECT DISTINCT `UID` FROM `ratings`";
$query3 = "SELECT `RID`,`rating` FROM `ratings` WHERE `UID` = $uid";


original php code:

$arrayAux=array();
$query2 = "SELECT DISTINCT `UID` FROM `ratings`";

$result2 = mysql_query($query2);

if(!$result2) return $arrayAux;

    while ($row2=mysql_fetch_array($result2,MYSQL_ASSOC)) 
    {
    $array2=array();
    $uid=$row2['UID'];

            $query3 = "SELECT `RID`,`rating` FROM `ratings` WHERE `UID` = $uid";
            $result3 = mysql_query($query3);
            if(!$result3) return $arrayAux;
            while ($row3=mysql_fetch_array($result3,MYSQL_ASSOC))
            {
                $rid=$row3['RID'];
                $rating=$row3['rating'];

                $array2[$rid] = $rating;
                }

    array_push($arrayAux, $array2);
        }
return $arrayAux;


Thank you!
select rid,rating,uid from ratings group by uid;