MySQL: 3 table join query? -
I have three tables (users, friends, posts) and two users (user 1 and user 2).
When user1 adds user2 as friend then user1 can simply view the post of user 2 but post only posts after date when user1 added user2 as user. My query is like:
$ sql = mysql_query (select from "P.P. friends at p.currentuserid = f.friendid and p. Time> f.friend_since or p> P .currentuserid = 'user1id' WHERE f.myid = 'user1id' command p.postid DESC LIMIT 20 ");
This is working perfectly but a little bit of a problem ..... !! This user2 displays users posts as user3 (as user of user 1) once, but the user shows 1 posts in several ways ....... ie
User2 Hi user1 Userssfsfsfsfsdf user1 Userssfsfsfsfsdf user3 Dddddddd user1 Sdfsdsdfsdsfsf user1 Sdfsdsdfsdsfsf
But why am I having this single entry / post in the database ........ !! !!
How can I fix this?
I am not a SQL expert, but I think your problem is in JOIN status. I can not see in a way that how you can get involved with posts and friends and get the results you need. A SQL expert can know this, but it is very difficult for me.
If I were you, then I would break the problem in two parts:
-
Select user's own post
-
Select the posts of the user's friend
For example, you can do this by using 2 different positions and friends in a sub-query Join the table (I have not tested it!):
select p from post * p.currentuserid = 'user1id' or p.postid in P2.postid to p2.postid to p2 .currentuserid = f.friendid where p2.time & gt; = Join the PO2 friend at f.friend_since and f.myid = 'user1id ")
Another way to do this is to use a union (it did not even test Has been ..): Select
select posts * p.currentuserid = 'user1id' select p2. P2.currentuserid = on f.friendid where p2.time & gt; = F.friend_since and f.myid = 'user1id'
Comments
Post a Comment