I have this table:
id
feed_id
...
Let\'s say that I have 500 rows and I want to select 3 entries for each feed_id? And 50 as total limit.>
You can do this with help of stored procedure.
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_feed`()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE a INT;
DECLARE cur1 CURSOR FOR SELECT id FROM test.id LIMIT 50;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur1;
REPEAT
FETCH cur1 INTO a;
IF NOT done THEN
SELECT * FROM feed_id WHERE id=a LIMIT 3;
END IF;
UNTIL done END REPEAT;
CLOSE cur1;
END$$
DELIMITER;