Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:43:57+00:00 2026-06-05T01:43:57+00:00

I have a select station as below which returns 2 rows: select ID, Title

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:43:58+00:00Added an answer on June 5, 2026 at 1:43 am
    DECLARE @i INT;
    
    SET @i = 1000;
    
    ;WITH n AS (SELECT TOP (@i) object_id FROM sys.all_columns)
    SELECT t.ID, t.Title FROM TableName AS t CROSS JOIN n;
    

    If you find that the CTE does not provide enough rows, you can always make more!

    DECLARE @i INT;
    
    SET @i = 1000000;
    
    ;WITH n AS 
    (
      SELECT TOP (@i) c.object_id FROM sys.all_columns AS c
       CROSS JOIN sys.all_objects AS o
    )
    SELECT t.ID, t.Title FROM TableName AS t CROSS JOIN n;
    

    …or you could create your own Numbers table:

    SET NOCOUNT ON;
    
    DECLARE @UpperLimit INT = 1000000; -- customize this
    
    ;WITH n AS
    (
        SELECT
            x = ROW_NUMBER() OVER (ORDER BY s1.[object_id])
        FROM       sys.all_objects AS s1
        CROSS JOIN sys.all_objects AS s2
        CROSS JOIN sys.all_objects AS s3
    )
    SELECT Number = x
      INTO dbo.Numbers
      FROM n
      WHERE x BETWEEN 1 AND @UpperLimit;
    
    GO
    CREATE UNIQUE CLUSTERED INDEX n ON dbo.Numbers(Number)
      -- if Enterprise Edition:
      -- WITH (DATA_COMPRESSION = PAGE)
    ;
    

    Now your query can be:

    DECLARE @i INT;
    
    SET @i = 1000000;
    
    ;WITH n AS (SELECT TOP (@i) Number FROM dbo.Numbers)
    SELECT t.ID, t.Title FROM TableName AS t CROSS JOIN n;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have folowing sql query select sta_name Station,count(factory_name) as factories from gps1 group by
I have a query: SELECT ID, Name, Distance FROM Station GROUP BY 'Distance approximation'
Let's say I have SELECT name FROM table which gives me something like foo
i have a table with columns ID,SUBJECT,BRANCH i have select the rows which satisfies
I have a select list which is being populated using the values from a
i have got that error and the line was this : $stations=$this->$db->query('SELECT * from
I have 2 tables, using an inner join to query them. SELECT COUNT(table2.id) FROM
Sorry if the title is confusing. Here is the query I have Select MONTH(DATE(TIMESTAMP)),
suppose I have SELECT * FROM table t GROUP BY j HAVING condition_one OR
I have a select query. I want to replace that select query with another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.