Is there a way to make rows repeat themselves several times in a query?
Lets say I have a table:
value count
A 2
B 5
C 1
D 3
E 4
I want a query that gives the result:
A
A
B
B
B
B
B
C
D
D
D
E
E
E
E
Each field repeat itself as much times as specified in the "count" value.
What I was thinking is to create another table(lets call it tableB. The table I described above will be tableA) containing a single integer field("number"), and fill it numbers from 1 to N. Than I make a query from both tables(without a join), so each field in tableA table will have N rows in the query - one for each field in table B. Finally I state that "number" must be smaller or equal to "count", so only "count" rows will be in the query for each field in tableA:
Now, this works, but it's kind of a clumsy method that can really slow things down with large tables. Plus, I have to keep N as low as possible to make the slow-down from getting too bad, which means I have to use a very low max-limit on "count"...
So, is there a better way to solve this?
Lets say I have a table:
value count
A 2
B 5
C 1
D 3
E 4
I want a query that gives the result:
A
A
B
B
B
B
B
C
D
D
D
E
E
E
E
Each field repeat itself as much times as specified in the "count" value.
What I was thinking is to create another table(lets call it tableB. The table I described above will be tableA) containing a single integer field("number"), and fill it numbers from 1 to N. Than I make a query from both tables(without a join), so each field in tableA table will have N rows in the query - one for each field in table B. Finally I state that "number" must be smaller or equal to "count", so only "count" rows will be in the query for each field in tableA:
Code:
SELECT tableA.value
FROM tableA, tableB
WHERE (((tableB.number)<=[count]))
ORDER BY tableA.value;
Now, this works, but it's kind of a clumsy method that can really slow things down with large tables. Plus, I have to keep N as low as possible to make the slow-down from getting too bad, which means I have to use a very low max-limit on "count"...
So, is there a better way to solve this?