別のテーブルから呼び出すときに、いくつかの SQL クエリに苦労しています。
2 つのテーブルから結果を取得しようとしています。この場合、user.id=1 から値を取得し、user.id=1 がフォローしているユーザーの値を取得したいと考えています。
しかし、常に同じfollow_idを持つすべてのユーザーまたはuser.id = 1の結果のみが得られます。
このようなことを考えていましたが、このクエリは空の結果を返します。
SELECT
user.email, user.username, tweets.message, tweets.date, userdetails.profile_img, userdetails.firstname, userdetails.lastname, following.id, following.user_id, following.follow_id
FROM user
JOIN userdetails ON user.id = userdetails.user_id
JOIN tweets ON userdetails.user_id = tweets.user_id
JOIN following ON following.follow_id
WHERE user.id = following.follow_id AND user.id = 1
テーブル。次の ID | ユーザー ID | follow_id
Tweets
user_id|id|date|message
user
id|email|password|username
userdetails
id|firstname|lastname|profile_img|user_id|about