研究目的で、ユーザーをフォローできる twitter そっくりのサイトがあります。今、ログインした人をフォローしているすべてのユーザーを取得したいと思います。
次のテーブルには 3 つの行があります。id、user_id、follow_id
ユーザー 1 がユーザー 2 をフォローする場合、行の値は次のようになりますuser_id = 1
。 follow_id= 2
しかし、同じ follow_id を持つユーザーを取得しようとすると、代わりに user_id 2 のみが返されます。そして、follow_id=2 を持つすべてのユーザーではありません
何か案が ?
SELECT
user.id, user.username, user.email,
userdetails.profile_img, following.follow_id
FROM
user
JOIN
userdetails ON user.id = userdetails.user_id
JOIN
following on user.id = following.follow_id
WHERE
following.follow_id = 2
うちのテーブルはこんな感じ
Following
id | user_id | follow_id
Tweets
user_id|id|date|message
user
id|email|password|username
userdetails
id|firstname|lastname|profile_img|user_id|about
任意のヒント ?