Solved

How to repeat rows over and over again

Posted on 2007-11-15
4
760 Views
Last Modified: 2008-02-01
I have this query that lists a given list of codes for a project

76011
76013
76015
76016

I want to have this query repeat 3 times so it comes out like this

76011
76013
76015
76016
76011
76013
76015
76016
etc..

0
Comment
Question by:PROJHOPE
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
MikeToole earned 125 total points
ID: 20290333
A new query wil the following SQL:

select Code from MyQuery
Union
select Code from MyQuery
Union
select Code from MyQuery
0
 

Author Comment

by:PROJHOPE
ID: 20290360
Sorry not explaining this correctly

Here is my query

select cost_element_id from DBSproj.dbo.component_cost_element
where component_id = '8933'
and project_id = 'INTL WITH TAS'

Results are this:

70573    
76013    
76023    
76033    
76053    
76063    
76093    
76313    
76333    
76353    
76373    
76393    
76473    
76493    
76613    
86013    
86033    
86933    

I want it to be

70573    
76013    
76023    
76033    
76053    
76063    
76093    
76313    
76333    
76353    
76373    
76393    
76473    
76493    
76613    
86013    
86033    
86933
70573    
76013    
76023    
76033    
76053    
76063    
76093    
76313    
76333    
76353    
76373    
76393    
76473    
76493    
76613    
86013    
86033    
86933    

etc...

If I do the union I simply retrieve only the 18

0
 

Author Comment

by:PROJHOPE
ID: 20290374
Ok I got it...UNION ALL not just UNION
0
 
LVL 27

Expert Comment

by:MikeToole
ID: 20290416
Oops, you got it!, I forget that my unions usually retrieve distinct rows, so no requirement for ALL.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question