$result=mysql_query("select * from signup_form where id IN(select friend_id from user_relationships where user_id=1)"); while($row=mysql_fetch_array($result)) { echo $row['username']."<br/>"; } Above is the example of subquery. Please change it by using JOIN because subquery is taking more time.
SELECT * FROM signup_form S [INDENT]INNER JOIN user_relationships R[/INDENT] [INDENT]ON S.ID = R.ID[/INDENT] [INDENT][INDENT]WHERE S.ID = 1[/INDENT][/INDENT] Code (markup):