2

Hey everybody. So, I'm creating this kind of a social network script for a project of mine and i need it to display a news feed similar to facebooks feed, that is, to display your friends posts and your own posts...but with my technique it only displays friends post.

my query is the following:

SELECT 
                * 
            FROM 
                ajee_friends
            JOIN
                ajee_wall
            ON
                ajee_friends.fid = ajee_wall.uid
            WHERE 
                ajee_friends.uid = '$this->uid'
4
  • @Ikke he wants to display friends posts and his own posts, this only displays his friends posts. Commented May 20, 2011 at 8:11
  • SELECT * FROM ajee_friends JOIN ajee_wall ON ajee_friends.fid = ajee_wall.uid AND ajeee_firends.fid = this->uid WHERE ajee_friends.uid = '$this->uid' if got it right Commented May 20, 2011 at 8:11
  • i will try skowron-line-s way, the problem is, that it doesnt show my own posts. Commented May 20, 2011 at 8:13
  • With posts, do you mean entries in the ajee_wall table? Commented May 20, 2011 at 8:16

3 Answers 3

5

If you want the wall of your friends and your own this can be done (in my opinion more readable as subselect):

SELECT *
  FROM ajee_wall w
 WHERE w.uid IN (SELECT fid FROM ajee_friends WHERE uid = $this->uid)
    OR w.uid = $this->uid
Sign up to request clarification or add additional context in comments.

1 Comment

Of course you will want to limit the ammount and also add something like a date condition. But this should be the basic.
2
    SELECT *
    FROM ajee_wall w
    WHERE w.uid IN
        ( SELECT fid 
          FROM ajee_friends
          WHERE uid = $this->uid
        )
UNION ALL
    SELECT *
    FROM ajee_wall w
    WHERE w.uid = $this->uid

2 Comments

@Asko: @Zoolway 's answer is equivalent (and shorter). Just check which one runs faster in your db (if that's an issue) or keep both saved somewhere.
I don't know, they both seem same fast to me. And great thanks to you all!
0

I think you can use Union all... something like,

SELECT * FROM ajee_friends UNION ALL SELECT * FROM ajee_wall

It'll show all of your post and your friends'. You can make it show just a few lines with limit.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.