I have two tables Posts and comments
Post Table
Post_id
Post_content
Comments table
comment_id
Comment
post_id
created_date
One post can have multiple comments or zero comments
My requirement is getting the latest comment for the posts using left outer join .
I mean result should be one record for the post with the below columns .
post_id,post_content ,comment_id,comment
In simple words posts should be getting along with their latest comment if it exists.
( Currently the system is getting the posts first and then going to the server again to get the latest comments to display , thought of getting them in one shot since we are displaying only one comment initially … Not sure what should be the best approach if wants to display more than one comment ..?)
Thank You
Regards
Kiran
BTW, you should consider indexing
Comments {post_id, created_date}for optimal performance, but be mindful of the non-primary key index overhead in case you are using InnoDB (see the “Disadvantages of clustering” section in this article).