Get data from 3 tables
I have 3 tables
- UserPosts(id, post, userfrom_id, userto_id, date)
- GroupPosts(id, post, group_id, userfrom_id, userto_id, date)
- CommunityPosts(id, post, community_id, user_id, date)
i want data from all theses 3 tables with related data like community name and image for community from community table (id, name, image)
similarly group's name and image from groups table and user, userfrom, userto's name and image from users table ordered by date
Now increasing the complexity a bit more UserPost has Many
- UserComments(id, userpost_id, userid, commentm date) and
- UserVotes(id, userpost_id,type, date) ps:type is like/unlike
Similarly GroupPosts have GroupComments ang GroupVotes and CommunityPosts has CommunityVotes and CommunityComments. i want this data too
Now increasing the complexity a bit more it needs to be ordered by comments too(no votes, phew). What mean is if a post is 1 month old but has the a comment that was put up 5 min AGO then i needs to be listed above a post posted 1 day ago with all comments greater than 5min.
Also in the result i would like to know if the particular record is a community record or a group record or a user record
This is sort off like a facebook homepage that shows all your, your gro开发者_Python百科ups and friends activity. I an using PHP(cakephp), Mysql. Hope i have given all the necessary data
Sounds like your are looking for JOIN
.
精彩评论