LIMIT amount of rows fetched by JOIN

Posted by user892134 on Stack Overflow See other posts from Stack Overflow or by user892134
Published on 2014-08-24T15:57:04Z Indexed on 2014/08/24 16:20 UTC
Read the original article Hit count: 187

Filed under:

How do i LIMIT the child rows fetched to only 5?

Here is the SQLfiddle http://sqlfiddle.com/#!2/bd96a/2. Right now it fetches all rows with parentid='4' and parentid='14'. It should only fetch 5 of each parentid. Assuming i have hundreds of rows, it should only fetch a max of 5 for each parentid.

 "SELECT child.* FROM mytable as parent
     LEFT JOIN mytable as child on child.parentid=parent.id
     WHERE parent.pageid IN ( 1, 2) AND parent.submittype='1'
     ORDER BY child.id ASC";

How do i solve this?

© Stack Overflow or respective owner

Related posts about mysql