1
我正在嘗試做一個MySQL查詢,它將顯示來自我和我的朋友的迷你博客。就像Twitter一樣。僅顯示來自我和朋友的迷你博客
這是我的桌子;
--members
m_id INT
m_user VARCHAR
(rest are other member info)
--shouts
s_id INT
s_userid INT
s_content TEXT
s_posted DATETIME
--friends
f_userid INT
f_friendid INT
f_status INT // 0=pending, 1=approved
f_create DATETIME
f_update DATETIME
注意:有2個條目1個友誼
例如:f_userid = ME,f_friendid = MYFRIEND並且反之亦然
f_userid = MYFRIEND,f_friendid = ME
的代碼有效,但不使用好友名單表;
SELECT * FROM shouts
JOIN members
ON members.m_id = shouts.s_uid
ORDER BY s_posted DESC
無法添加好友表信息。
我認爲我只是缺少的代碼或2一行...
我想這一點,但沒有成功。
SELECT * FROM shouts
JOIN members
ON members.m_id = shouts.s_uid
JOIN friends
ON friends.f_friendid = members.m_id
WHERE m_id = 1 //my id
AND f_userid = 1 //my id
AND f_status = 1
ORDER BY s_posted DESC