Bạn có thể sử dụng phép nối bảng (ví dụ: http://dev.mysql .com / doc / refman / 5.0 / vi / join.html ) để tìm tất cả các yêu cầu.
Trên thực tế, bạn có thể sử dụng một truy vấn con tại đây:
SELECT * FROM users_status WHERE userid = "$userid"
OR userid in (SELECT request_to FROM friendships where request_from = "$userid" AND friendship_status = 1)
OR userid in (SELECT request_from FROM friendships where request_to = "$userid" AND friendship_status = 1)
thay thế $userid
với id người dùng của bạn