Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Combining several rows in the view


Message #1 by "Peter Afonin" <pafo@s...> on Wed, 23 Oct 2002 20:29:09
Peter,

You can do that only when you have identical output from all of your queries, in terms of data type and number of columns.

It can be done using UNION operator as given below.

Select x, y, z, from test1
Union All
select a, b, c from test2
when a is identical to x's properties, b to y, and c to z, also both the queries have the same number of columns/fields.

But in your case you have 3 fields in one's output and 4 fields in the other's even I see 5 from another(if I am right). So I dont
think it is possible. But not sure, if any workaround can be done to that.
______________
Cheers!!!
Vijay G

Peter Afonin <pafo@s...> wrote:
Hello: 

Could you please recommend me some code how to combine several rows in the 
view into one, assuming all fields are the same except one. 

I have: 

Order Form Comments

11111 AAA aaaaaaaaaa
11111 AAA bbbbbbbbb
11111 AAA cccccccccc 
22222 BBB kkkkkkkk 
22222 BBB lllllllllllll 
33333 BBB mmmm 
............... etc.

I need to have: 

11111 AAA aaaaaaaa bbbbbb cccccc 
22222 BBB kkkkkk lllllllllll 
33333 BBB mmmmm 

So I need to have one record instead of three which would combine Comments 
from the three previous records, assuming that the Order and Form are the 
same in all three records (Combination Order and Form is a Primary Key). 
I can do it in VB, but I presume there is an easier and more efficient way 
in SQL. 
I would appreciate your help very much. 

Thank you, 

-- 
Peter Afonin


---------------------------------
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site

  Return to Index