(
SELECT u.username, u.picture, m.id, m.user_note, m.reply_id, m.reply_name, m.dt
FROM relationships r
JOIN notes m ON m.user_id = r.leader
JOIN user u ON r.leader = u.user_id
WHERE r.listener ='2'
)
UNION ALL
(
SELECT u.username, u.picture, m.id, m.user_note, m.reply_id, m.reply_name, m.dt
FROM notes m
JOIN user u ON m.user_id = u.user_id
WHERE u.user_id ='2'
)
WHERE dt > '2010-09-20_131830'
ORDER BY dt DESC
what this deos is it queries the user(loggedin), people they follow and retrives thier messages. tables are shown below,!
what i want to add to this query, is also the user(loggedin) updates aswell. but obviously the user deosnt follow himself. whats the best way i can do this!!
user_table
user_id | username
-------------------
1 | solomon
2 | muna
message table
id user_id| message
---------------------------------------
1 1 | this is my first message
2 1 | this is my second message
3 2 | this is muna message
relationship table
leader | follower
------------------
1 | 2