I have a select station as below which returns 2 rows:
select ID, Title from TableName
(The actual query is quite large and returns much more rows but for simplicity assume the above.)
I’d need a query which returns more data and I can’t change the database table.
How to multiply/duplicate and increase the number of rows which are returned by e.g. 5 times so that 10 rows are returned instead?
I know with UNION ALL it’s possible if I write it 5 times:
select ID, Title from TableName
UNION ALL
select ID, Title from TableName
UNION ALL
select ID, Title from TableName
UNION ALL
select ID, Title from TableName
UNION ALL
select ID, Title from TableName
But is there any other simpler way? My actual query is much larger and so can’t use UNION ALL.
I hope the questions is clear.
If you find that the CTE does not provide enough rows, you can always make more!
…or you could create your own Numbers table:
Now your query can be: