[英]Retrieve user profile data from all of a user's friends using php and mysql
我在網上搜索了幾個示例,但在研究后仍然需要一些幫助。 我有2個表:用戶和朋友。
users表包含以下列:
朋友表具有以下列:
我希望能夠從作為指定用戶(initiator_user_id)的朋友(friend_user_id)的所有用戶中獲取用戶名,profile_picture,狀態,status_message。 經過研究,我相信這是通過工會完成的。
我已經嘗試過下面的查詢,但是不起作用:
SELECT friend_user_id
FROM friends
WHERE initiator_user_id = 1001 //gets all the id's of the friends of user 1001
UNION All
SELECT profile_picture, status, status_message, username from users
WHERE friend_user_id = id //gets all the profile data of user's profiles that are friends of user 1001
我需要的是要向所有朋友顯示朋友數據:
我的問題:
使用簡單的INNER JOIN:
SELECT u.*
FROM users AS u
INNER JOIN friends AS f ON f.friend_user_id = u.id
WHERE f.initiator_user_id = 1001
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.