テーブルの友達がいるとしましょう
user_1 | user_2
次に、これらの友達が何をしているかを知りたいので、posts テーブルと updates テーブルをチェックします。
post_id | post_title | post_message | user_id | timestamp
update_id | title | userid | timestamp
私は次のようなロジックを実現したいと考えています: 友達のリストを取得し、この生成された友達のリストを調べて、最初に最新のアクティビティ (タイムスタンプ) で並べ替えて、何かを追加したかどうかを確認します。
Select user_1 from friends where user_2 = '$my_userid'
union
Select user_2 from friends where user_1 = '$my_userid'
//now loop through each of these friends and check the update/post tables to see if they have added anything recently
これをすべて 1 つの MySQL クエリで実行できますか? それとも分割して PHP を使用する必要がありますか?