SELECT p.*
FROM StatusUpdates p
JOIN FriendRequests fr
ON (fr.From = p.AuthorId OR fr.To = p.AuthorId)
WHERE fr.To = ".$Id." OR fr.From = ".$Id."
AND fr.Accepted = 1
ORDER BY p.DatePosted DESC
I’m using this SQL code at the moment which somone wrote for me on a different question. I’m using PHP, but that shouldn’t make much difference, since the only thing I’m doing with it is concatenating a variable into it.
What it’s meant to do is go through all your friends and get all their status posts, and order them. It works fine, but it picks out “$Id”‘s posts either not at all, or the amount of friends you have
Eg, if you had 5 friends, it would pick our your posts 5 times. I only want it to do this once. How could I do this?
You need to use
LEFT JOINinstead of join if you want to display post id regardless of number of friends. AndGROUP BY p.idin order not to display the same posts more than 1 time: