私はかなり頭がおかしいので、前に間違った質問をしました。今、これが私が達成しようとしていることです。
user.id = 1
フォローしているユーザーの値と値を取得しようとしていuser.id = 1
ます。
しかし、私はエーテルから結果を得るuser.id 1
か、この場合は次のfollowing.follow_id = 2
. 何か案は ?
表示用の SQLfiddle を作成しました。ご覧のとおり、得られる唯一の結果は user_one からのものです。
http://sqlfiddle.com/#!2/6a39f/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
LEFT JOIN following ON user.id = 1
WHERE following.user_id = 1
テーブル:
つぶやき
ユーザー ID | ID | 日付 | メッセージ
ユーザー
ID | 電子メール | パスワード | ユーザー名
ユーザー詳細
ID | ファーストネーム | 姓 | プロフィール画像 | ユーザー ID | 約
続く
ID | ユーザー ID | follow_id
この場合、次の表に値があります
user_id = 1 and follow_id = 2
まとめ 。
User_id = 1 is following follow_id = 2
しかし、私user_id = 1
は両方からではなく、結果のみを取得します。ありがとう。
基本的に、この 2 つのクエリを結合しようとしています。
フォローしているユーザーから結果を取得するためのクエリ。
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 following.follow_id = tweets.user_id AND following.user_id = '1' ORDER BY tweets.date DESC
そして、ユーザー 1 の値を取得するためのクエリ
SELECT user.email,
user.username,
tweets.message,
tweets.date,
userdetails.profile_img,
userdetails.firstname,
userdetails.lastname
FROM user
JOIN userdetails ON user.id = userdetails.user_id
JOIN tweets ON userdetails.user_id = tweets.user_id
WHERE user.id = '1' ORDER BY tweets.date DESC