I have three database tables: users, user_profiles and friends:
users
user_profiles
friends
Some modification to eugene y's answer, will this work?
SELECT * FROM users u JOIN friends f ON (f.userb_id = u.id OR f.usera_id = u.id) JOIN user_profiles p ON u.id = p.user_id WHERE u.id = ?