mysql - Posts, comments and advanced sql filtering -


i have database table of posts. have db table comments, column comment_id (ai) , column post_id it's attached to.

i want make query list of posts once, sorted last posted comment.

the problem can't figure out sql query it. whatever try comments listed too. i'm skilled or experienced mysql, tried using different "joins". there way it?

select distinct p.* posts p, comments c  p.post_id = c.post_id order c.time desc  

i assumed relational schema. might need adapt query.

alternative: create view last_comment_time field.

create view posts  (select *, (select time comments post_id = p.post_id order time desc limit 1) last_comment_time  posts p); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -