How to repeat row based on qty field I have a table like

id product qty
1  apples  3
2  oranges 1


I want to get a query that will return 

1  apples  1
1  apples  1
1  apples  1
2  oranges 1


How do I accomplish that? I've seen several answers on splitting a column into rows like "a,b,c" but not on qty like this. Any help is appreciated.
You need a table of numbers, and fill this table with sequential number as much as you want.

CREATE TABLE numbers (
    number int
)
ENGINE = InnoDB;

INSERT INTO numbers (number) VALUES (1), (2), (3), (4), (5); -- you can add more number according your needs.


And then join this table with your table.

SELECT p.id, p.product, 1
FROM products p
     JOIN numbers n ON p.qty &gt;= n.number;


This should produce result as you want.

If you can't create table, you can simulate table with UNION.

SELECT p.id, p.product, 1
FROM products p
    JOIN (
                SELECT 1 as number UNION
                SELECT 2 UNION
                SELECT 3 -- you can continue this line
               ) n
    ON p.qty &gt;= n.number;