Mysql 2 Tables join Limit Result return from both Table -


I am trying this requirement for a few hours, but I do not know that I'm not getting the desired result .

I have two tables.

  ** Main comment table ----------------------------- ------ ----------------------------------------- ID | Comments | Date_commented | On comment_ | Comment 1 by 1 hello world ********* 321 123 hair comment table ----------------------------- - --------------------------------------------- ID | MainpostID | Child_comment_data | Comment | Hetto World's 1st Child's Comment # 456 ********************************************************************* My requirement: 
I want to retrieve the first 10 main comments with each other for chillmement. Main Comment I would like to limit the number of child annotations for each main comment.

What I tried:

  SELECT maincomment.comments, maincomment from childcomment.child_comment_data maincomment LEFT JOIN.ID = Basic comment. MySpotid and Main Comet Dot Commendants = Child Comment Dotmed by WHERE maincomment.id = childcomment.mainpostID Date Posted DESC LIMIT 10   

Result: I'm receiving just 10 key notifications each The main number of children for the main comment is just 1. I have to return 5 children's work to everyone's needs.

Anyone will help with some tips / questions.

Thank you very much.

You can use this solution:

  SELECT a . *, B * FROM (SELECT * 10 from the DESC limit posted on the date of the main order) Include a bottom (Select one. *) Join one of the children's education on B. B. Maiposted and B.Mimopostid AID and LT; = AID Hewing COUNT (1)   

This latest 5 comments of the latest child gets up to 10 latest keynotes, if any special comment If there is no child comment, child-comment data will include the NULL value.

Comments