php - select query with 2 tables -
i have page people can post comments , page people can click "follow" on other people profiles (same on facebook)
i have select query post comments have, order them follow way: first, print 2 newest comments (they must been posted week) of lastest people click follow. second, post rest of posted, order them create-date
(i'm using linux time)
can me sql query?
this current select query. pull comment create-date:
select id, userid, text, createdate `comments` comment (comment.refid = 0) , (comment.pagename = 'yard') , 1=1 order comment.createdate desc limit 0, 20
"followers" table looks this:
userid ownerid createdate 1 2 1439019657 1 4 1438940399
"comments" table looks loke this:
id userid pagename refid text createdate 220 1 yard 0 text1 1438030967 227 1 yard 0 text2 1438031704 228 1 yard 0 text3 1438031704
i might've messed followers' relations. example data looks incoplete full context. shows userid=1 comments sure, either no 1 follows userid=1 or both 3 , 4 follow him. no idea refid doing in comments table. query shows concept anyway - you'll figure out details.
select un.* (( select 1 priority, comment.id, comment.userid, comment.text, comment.createdate `comments` comment inner join `followers` follower on follower.userid = comment.userid comment.refid = 0 , comment.pagename = 'yard' , ... order follower.createdate desc limit 2 ) union distinct ( select 2 priority, id, userid, text, createdate `comments` comment comment.refid = 0 , comment.pagename = 'yard' )) un order un.priority, un.createdate desc limit 20
Comments
Post a Comment