Avatar of jockmahon01
jockmahon01
Flag for United States of America asked on

Returning a column into a comma list as part of another select stmt

Hey i need to do a select on a table which will return maybe five rows, then i need to take one column from this rs and put it as a column of another rs

how do i do this please
Oracle Database

Avatar of undefined
Last Comment
jockmahon01

8/22/2022 - Mon
SOLUTION
erwin_huybregts

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Muhammad Khan

or

select t1.col1,t1.col2,t2.colc
from table1 t1,table2 t2
where t1.col1=t2.colA
erwin_huybregts

I think what he's trying to do is a little more complicated, my example is bad which I posted there.
In the case of my example you are complete right aiklamha.

grtz.
jockmahon01

ASKER
SOrry , left out the critical part of this
i need to put the inner select into the outer select as a column of comma seperate values

ie select from table

do inner select and get maybe five rows and convert into a comma list

then put this list into the first select as a another column

sorry about that didnt read what i posted

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SOLUTION
Muhammad Khan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
erwin_huybregts

I think I understand what you mean now.
The scripts below should be able to do this.

You can use either one of them according to what are your further needs with this query.
select t1.col1, t1.col2, t2.csvCol
from table1 t1,
   (select colA|| ',' ||colB|| ',' ||colC as csvCol from table 2) t2
where t1.linkingKey = t2.linkingKey
 
---------------------------------------
 
select t1.col1, t1.col2, t2.colA||','||t2.colB||','||t2.colC as csvCol
from table1 t1, table2 t2
where t1.linkingKey = t2.linkingKey

Open in new window

Muhammad Khan

erwin_huybregts, i think he's not only asking to append columns.. but rows also...
erwin_huybregts

As jockmahon01 explained in his last comment I think it's clear he just wants to treat the select from the inner query as a column in the outer query. And the column needs to be a list of comma separated values using the columns from the inner query.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
erwin_huybregts

Ow my apologies misread something here:

do inner select and get maybe five rows and convert into a comma list

Then I think you can solve this with PL/SQL code but not in a simple query, as you need to use multiple rows.
dbmullen

can you provide some sample data and the results you expect from it?
SOLUTION
gajmp

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Dr_Billy

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jockmahon01

ASKER
thanks all
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy