php - Sorting a MySQL query based on another query? -
i'm building simple forum software sort of self-test php , mysql skills, i'm not quite sure how accomplish task. have table called threads contains list of threads. have table called posts, contains posts. each table's primary key auto-increment id. each row in posts contains id of thread belongs to.
while can retrieve of threads in subforum query this:
select * threads forumid='$forumid' ...i'm not sure how sort based on latest post each thread. can posts given thread this:
select * posts threadid='$threadid' ...but don't know how incorporate data initial query sort it. since each post has unique id, posts higher ids more recent, there's no need compare dates or that. i'm unclear on how query.
i'm pretty sure possible in mysql, if it's not, efficient php solution? thanks!
try inner join
select p.*,t.* threads t inner join posts p on t.id = p.threadid order //whatever column want p.date p.date desc
Comments
Post a Comment