SQL Multiple Columns Displayed in a Single Row

Hello everyone,
I have 2 tables, Product and Product_Name, one Product can have more than one name.
I need to retrieve it in such a way that I show the Product_ID followed by all the names this product has.
I'm not able to make it, every way I try I get the Product ID duplicated and several rows with a different product name on each row as follows:
1, 'Iron Z"
1, 'Iron M'
1, 'Iron N'
2, 'Wood P'
2, 'Wood M'
What I need is:
1, Iron Z, Iron M, Iron N
2, Wood P, Wood M
Thanks and Regards.

Hi,
user10103934 wrote:
Thank you for the answer Frank,
Iron Z, Iron M and Iron N would be 3 different entries on the same column.
I'm sure the LISTAGG function would resolve this, the problem is that I was hoping to get a solution on pure SQL or PL/SQL, maybe with a nested Select.
My Oracle version is 10g Express Edition.LISTAGG is pure SQL, but it was only introduced in Oracle 11.2. Everything mentioned below should work in Oracle 10.
The STRAGG function from that page is very useful. You have to copy and install about 60 line of PL/SQL code. Do that once, and then you can use it hundreds of times in hundreds of queries, just as if it was a built-in function. The main problem with STRAGG is that it's hard to get soprted output from it. There's a modified version, designed for sorted output, on this thread:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:15637744429336
Never used it. Can't vouch for it.
SYS_CONNECT_BY_PATH seems to be the most popular way of doing string aggregation in Oracle 10. The example given on the Oracle Base page (which I posted in my last message) is a little clumsy and inefficient. See the following thread for a better example, using CONNECT_BY_ISLEAF:
Re: Concatenate strings from more rows into one row.
or, now that I see it, Pollywog's example above.
Edited by: Frank Kulash on Jun 11, 2010 2:24 PM

Similar Messages

  • How to refer a column value of a single row in conditional column display?

    Hello,
    does anybody have an idea, how i can refer a column value of a single row in conditional display of a column?
    So my idea is, that a report has a column, which value is only displayed, when another column value of this row has a specific value.
    I want to solve this problem with condition type: PL/SQL Function Body returning a boolean.
    But I do not know how to refer the column value of each single row!
    Thank you,
    Tim

    Here's a solution that, to me, seems easier to implement but, that's, of course, in the eye of the implementer.
    Rather than using APEX to generate a link column for you, actually create the link as part of your SQL.
    select '<a href="f?p=102:3:491847682940364::::P3_CONTACT_ID:' || CONTACT_ID || "><img src="/i/themes/theme_1/ed-item.gif" alt="Edit"></a>' CONTACT_LINK, ...
    etc.
    Test this out. You'll see that it works just like making a column a link using the column attributes.
    Next, we'll change the SQL to use a DECODE statement to either display the link or nothing depending on what your criteria is. For example, let's assume you only want a link for active contacts.
    select Decode( CONTACT_STATUS, 'A', '<a href="f?p=102:3:491847682940364::::P3_CONTACT_ID:' || CONTACT_ID || "><img src="/i/themes/theme_1/ed-item.gif" alt="Edit"></a>', NULL ) CONTACT_LINK, ...
    etc.
    This will not display the link in any rows in which the CONTACT_STATUS is not active, i.e. "A"
    -Joe

  • Unable to reorder/change column names on interactive single row view

    I have created an interactive report and grouped my columns to display nicely in a single row view report. However, once I initially add the columns to a group, I am unable to reorder them. I can move them up and down the list, but the changes don't save. Also, I have gone through column by column and unchecked the box that says Use Same Text for Single Row View and expanded the column name. However, the single row view still displays what is in the master report. I've tried closing out my browser completely and reopening, but I am still not seeing my changes. Any suggestions?

    I also just stumbled about the "Use Same Text for Single Row View" option actually doing nothing - in Single Row View I still get the label text from "Column Heading", no matter what I enter in "Single Row View Label".
    I had to adjust a column width using a span tag in the heading (as this seems to be the only way to do that - any other suggestions I found adding style information to the region header had no effect), and now that tag is displayed in the Single Row View label.
    I can live with that for now, but it's not really nice.
    Is this a known bug? Didn't find anything else in the forum regarding this problem so far.
    Holger

  • Can we make a fact column to be displayed as a single ROW in obiee 11g

    Hi,
    I have a requirement recently, where i need to show a fact column which shows the total value, as a single row in the main report.
    Total
    1000
    1000
    1000
    1000
    Changed to..
    Total
    1000
    Can we achieve this in OBIEE.
    Please share your inputs. Much Appreciate it !
    Thanks,
    Ramya

    Shailja,
    Yes you can. Follow these steps:
    1> Create the LOV (which you can create from another table, as you mention). and test it.
    2> Now you create one ADF Table on the page.
    3> Select the Table in staructure window > select af:column(the column where you want put you lov) > Inside the af:column, Replace the Uicomponent by the LOV(which you created in step-1)
    4> Save & Run
    --Neelmani Jaiswal
    http://www.jneelmani.blogspot.com

  • Multiple pages that edit a single row

    I have searched on tabs and editing a single row using multiple pages and I am confused. I don't want to use java as I am trying to not learn that too...
    What I am trying to do sounds like it has been explained before but let me do this again...
    I have a record that is too large to fit on a single screen. This makes for a cumbersome entry process. The record is actually broken into four "logical" chunks. Main, Sub1, Sub2 and Sub3.
    I have made a list that will allow the record to be selected and call the first logical page... L1.
    I have made tabs that show all the pages and allow me to navigate between them quickly.
    When I get to L1 all the data is there. I may not change any data on that page and go directly to L2 through L4. However the record is not brought forward onto those pages. So the pages are not related (and I don't have the terminology right I know :) and I could "link" the pages. So here is what I would like the application to do;
    1. Display a list and allow the user to select the record to edit.
    2. Upon edit go to the first page (tab).. this works
    3. Allow the user to select a tab and the page displays the data for the record selected
    4. Allow the user to complete the edits and save the record. Upon save the user is returned to the list in step 1.
    I was thinking there are several ways to do it... but I was hoping someone could save me a bunch of trial and error (emphasis on the error) ...
    1. When navigating off the page save the record, pass the key and re-read the record... ugly huh?
    2. Pass all the session data for the record over to the next screen. Is that possible? e.g pxx_field1 = pyy_field1
    The the question was does a template with two level tabs keep the record data between tabs?
    Any help is greatly appreciated.
    Sam

    I think this works... kinda
    1. I have a "list" that allows the selection of the item to edit.
    2. That list opens a page that is the "header" page for a tab set.
    3. Each page in the tab set uses the same "ID" to read the record and display the columns. That is how it would work if the list called each individual page.
    4. I modified the "slave" tabs to have the "ID" of the "header" page.
    This displays the correct data on each page. And it looks like the "apply changes" button saves the changes on the page.
    Caveats inlclude (I think as I haven't done exhaustive testing"
    1. "apply changes" must be done at each page where there were changes or they would be lost.
    2. The first dispaly of the page is blank. Clicking on the tab a second time displays the data. This is true if it is the first time a user selects a record in a session (the "slave" tabs are blank) or if it is a subsequent record update (the "slave" tabs have the last records data.
    Thoughts... is this really boring to everyone but me?
    Sam

  • Comparison of multiple column values with a single column value

    I have two separate tables say Tab1 and Tab2
    I want to select some datas , which is common to both the tables.
    In tab1 , there is a column 'STATE' and it's value is 'A'
    In tab2, there are multiple columns for the state, say STATE_A,STATE_B, STATE_C ETC and a row is present with the following details
    STATE_A = 1, STATE_B =1 ,STATE_C =0,STATE_D=1
    I need to select STATE when STATE_A ='1',
    if my STATE='B', this STATE has to be selected since STATE_B =' 1', similraly
    if my STATE='D', this STATE has to be selected since STATE_D =' 1',
    If my STATE='C', STATE_C should not get selected since it's '0'.
    Is it possible to do this in a single SELECT statement, where I have some other checks also or else how can I achieve it?

    Maybe this will help
    Select * from STATE_MAS ;
    STATE
    A
    B
    D
    F
    H
    Select * from STATE_CHILD
      STATE_A   STATE_B   STATE_C   STATE_D   STATE_E   STATE_F   STATE_G   STATE_H   STATE_I   STATE_J
            1         0         0         1         1         0         0         0         0         0
    CREATE OR REPLACE FUNCTION GET_STATE (P_VAL VARCHAR) RETURN NUMBER IS
    V_SQL VARCHAR2(200);
    V_COL VARCHAR2(35);
    P_RETURN NUMBER ;
    BEGIN
    V_COL := 'STATE_'||P_VAL;
    V_SQL := 'SELECT 1 FROM STATE_CHILD WHERE '||V_COL||' = 1 ';
    EXECUTE IMMEDIATE  V_SQL INTO P_RETURN ;
    RETURN P_RETURN ;
    END;
    SELECT STATE FROM STATE_MAS
    WHERE GET_STATE(STATE) = 1 ;
    STATE
    A
    D

  • Exclude column from ir in single row view

    Hi Folks,
    my prob: I have a very long long column (url) in my ir. In my report view I want to show it shortended and in my single row view I want to show the whole value.
    So my query looks like:
    select long_url, substr(long_url, 1, 30)||'...' short_url
    from something;
    Then I exclude the long_url column interactively with the "select columns" option in the Actions menu and save the report as standard.
    Now my ir shows only the short_url in the report view, what is ok. But in the single report view it show both long_url AND short_url.
    I want to get rid of the short_url in single row view. Is there any way without creating a custom form page?
    Thanks!

    same question in other words: is there an apex variable to distinguish the report view from the detail view?
    please help!

  • Multiple column display of a dataset

    We're looking for an example (or explanation0 of a customized data web bean that displays the data in multiple columns rather than the "default":
    First Name: John
    Last Name: Doe
    Dept: Acct
    Salary: 100,000
    We would like:
    FName: John LName:Doe
    Dept.: Acct. Salary: 100,00
    Any leads as to how to approach this formatting issue would be much appreciated!
    Thanks,
    Scott
    null

    Hi,
    I had the same problem, stupid indeed.
    I changed the ViewCurrentRecord Implementation of the DataWebBean, in the render method.
    The JSP is lot of incomplete things.
    Be aware that JSP is also till now not multiuser - able !!!!!!!
    Seb.

  • Display data in single row

    i have table dept of deptno d001,d002,d003,d004
    i want to list the data like below
    deptno
    d001,d002,d003,d004 ( in a single row)
    is it possible..?
    S

    Based on your database version you can try any one of the following http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

  • Get the column values in a single row seperated by commas

    Hi
    i have two tables project_baseline and project_resource which have the foreign key project_id from the base table project_details. Now iam trying to retrieve data from these tables using the below query :
    select distinct b.TASK_NAME,r.RESOURCE_NAME,() from project_baseline b inner join project_resource r on R.PROJECT_ID=B.PROJECT_ID group by b.TASK_NAME,r.RESOURCE_NAME
    Below is the output snippet :
    TASK_NAME RESOURCE_NAME
    TEST DESIGN PARAGI M
    TEST DESIGN RAJAN M S
    TEST EXECUTION VIBHU ARMA
    TEST EXECUTION PRATHAB GARG
    TEST EXECUTION NAGABHUSHAN G K
    TEST DATA PREPARATION RAJAN M S
    TEST DATA PREPARATION SHIVA MARAN
    TEST CASE REWORK VISWAN RAM
    TEST CASE REVIEW NAGABHUSHAN G K
    REGRESSION SANGEET
    PROJECT SUPPORT VIBHU ARMA
    PROJECT SUPPORT PRATHAB GARG
    PROJECT SUPPORT PARAGI M
    PROJECT SUPPORT NAGABHUSHAN G K
    PROJECT SUPPORT SANGEET
    PROJECT CLOSURE PRATHAB GARG
    i need to get the resource_names in a single row seperated by comma for a single task like following:
    TASK_NAME RESOURCE_NAME
    PROJECT SUPPORT VIBHU ARMA,PRATHAB GARG,PARAGI M,NAGABHUSHAN G K,SANGEET
    Could anyone please help me to get the query for the above formated output?
    Thanks in advance
    Meera
    Edited by: 928378 on May 22, 2012 5:20 AM

    Hi,
    It can be done using xmlagg function.
    For Example :
    Table Data..
    DEPTNO     ENAME
    20     WARD Tree
    23     Shank
    30     BLAKE
    10     MILLER
    30     MARTIN
    10     CLARK
    20     SCOTT
    30     TURNER
    20     ADAMS
    30     JAMES
    20     FORD
    30     BLAKE
    Query:
    SELECT deptno,
    RTRIM (XMLAGG (XMLELEMENT (e, ename || ',')).EXTRACT ('//text()'),
    ) NAME
    FROM emp
    GROUP BY deptno;
    Output :
    DEPTNO     NAME
    10     MILLER,CLARK
    20     WARD Tree,FORD,ADAMS,SCOTT
    23     Shank
    30     BLAKE,TURNER,BLAKE,JAMES,MARTIN
    Thanks,
    Shankar
    Thanks,
    Shankar.

  • Multiple column headers in a single DataGrid?

    Suppose i wanted to display information on, say, invoices.
    So, i want to display one part of my DataGrid with only invoices from the last 30 days, the next section for 30-60 days old, and the third section is 90 days+ old.
    I want it to look, basically, like this:
    30 Days or less
    Customer         Days Old         amount
    Mr. X cleaning           15                20.76
    7-11                             3                   7.11
    30-60 days old
    Customer         Days Old         amount
    Barney's                  75                 12.34
    Watto's part shop    80              1200.89
    90 days or older
    Customer         Days Old         amount
    Sprint                   144                  30.63
    Is it possible to do this in a single DataGrid? I want the mulitple column headers, but want to be able to get rid of them and combine all this data into a single DataGrid with all invoices, if needs be. In that case all but the top column header titles would disappear.
    Any info on this is appreciated.
    thanks!

    Hi,
    You can do grouping with advance datagrid.
    http://livedocs.adobe.com/flex/3/html/help.html?content=advdatagrid_02.html
    Rgds
    Johnny

  • Popup List with multiple columns but returning a single column (key value)

    Hi,
    1. Is it not possible to show a POPup (returning a key value) or Select list with more than 1 column? If so how?
    2. I have an item in a page which should be hidden if 1 particular button was pressed. This is is to use the same page but have some behavioural change based on which button (option) was selected. How can I get the name of the BUTTON PRESSED TO INVOKE THIS PAGE.
    thanks
    SebJos

    Hi,
    In that case, you should make the page item conditional. There are many techniques to do this but it would depend on what the button is for.
    As a simple example...
    1 - Create a hidden item on your page called, say, Pn_SHOW (replace n with your page number - eg, P1_SHOW). Set the default value of this item to either 0 (zero) or 1 - 0 will hide the item and 1 will display it, so in your example, set it to 0
    2 - On the page item you want to show/hide - on its definition, you have a Conditions section. Set the following:
    Condition Type: Value of Item in Expression 1 = Expression 2
    Expression 1: P1_SHOW
    Expression 2: 1
    When the page is loaded, because the value of P1_SHOW is 0, and due to the conditions we have just set (where P1_SHOW must be 1 for the item to be shown), the item will not appear on the page.
    When you created your button, a new page branch should have been created. On this branch, you have two settings - "Set these items" and "With these values". Set the following:
    Set these items: P1_SHOW
    With these values: 0
    You should also have at least one other branch on your page - one of these will need to set the value of P1_SHOW to 1 to get the item to display.
    Andy

  • Template:Multiple field result in a single row, comma separated

    Hello,
    without* having to write a function in Pl/SQL, is it possible, when I have this query,
    select     
          "DOSSIER"."ID" as "DOSSIERID",
          "DOSSIER"."TITLE" as "TITLE",
          "DVD"."ID" as "DVDID",
          "DVD"."NAME" as "DVDNAME",
          "DVD"."ID_DOSSIER" as "DVD_ID_DOSSIER",
          "ELEMENTS"."ID" as "ELEMENTSID",
          "ELEMENTS"."NAME" as "ELEMENTSNAME",
          "ELEMENTS"."ID_DVD" as "ELEMENTS_ID_DVD"
    from      "DOSSIER" "DOSSIER",
               "DVD" "DVD",
               "ELEMENTS" "ELEMENTS"
    where   "DVD"."ID_DOSSIER"="DOSSIER"."ID"
    and      "ELEMENTS"."ID_DVD"="DVD"."ID"
      and       "DOSSIER"."TITLE" = 'FIGARO'**Instead of having this result ( with break in the template)*
    FIGARO    C2008-203   12l10201.tif
                        12l10202.tif
                        12l11101.tif
                        12l11102.tif
                        12l11201.tif
                        12l11202.tif
                        12l12101.tif
                        12l12102.tif
              C2008-204     12l12202.tif
                        12l13101.tif
                        12l13102.tif
                        12l13201.tif
                        12l13202.tif
                        12l14101.tif
                        12l14102.tif
                        12l14201.tif
                        12l14202.tif
                        12l15101.tif
                        12l15102.tif
                        12l15201.tif
                    C2008-205     12l15202.tif
                        12l16101.tif
                        12l16102.tif
                        12l16201.tif
                        12l16202.tif
                        12m01101.tif
                        12m01102.tifhaving this result, WITH the element only, comma separeted??? ( I can have from 0 to 500 elements)
    FIGARO
    DVD:        C2008-203
    Elements:  12l10201.tif, 12l10202.tif, 12l11101.tif, 12l11102.tif, 12l11201.tif, 2l11202.tif, 12l12101.tif, 12l12102.tifthanks, Roseline

    This should help you http://tkyte.blogspot.com/2007/03/stringing-them-up.html

  • How to convert multiple string values in a single row from nvarchar to int

    suppose I have a table like below.all these values are in nvarchar. How would I find the minimum year from START_DATE??
    PRODUCT_CODE 
    PRODUCT_DESC
    START_DATE
    P00002933
    VITAMINE C
    2005,2000,2011,2001,2002
    P00003087
    BIOFENAC
    2011,2009,2006,2007,2004,2005
    P00000155
    AMOXYPEN
    2006,2007,2008,2009,0000,2001
    P00002325
    SAHHA FARINE
    2008,2003,2002,2001,2009
    P00005666
    AMOXYPEN
    2007,2008,2006,2009,0000,2001

    Create the split function:
    CREATE FUNCTION Split (
    @InputString VARCHAR(8000),
    @Delimiter VARCHAR(50)
    RETURNS @Items TABLE (
    Item VARCHAR(8000)
    AS
    BEGIN
    IF @Delimiter = ' '
    BEGIN
    SET @Delimiter = ','
    SET @InputString = REPLACE(@InputString, ' ', @Delimiter)
    END
    IF (@Delimiter IS NULL OR @Delimiter = '')
    SET @Delimiter = ','
    --INSERT INTO @Items VALUES (@Delimiter) -- Diagnostic
    --INSERT INTO @Items VALUES (@InputString) -- Diagnostic
    DECLARE @Item VARCHAR(8000)
    DECLARE @ItemList VARCHAR(8000)
    DECLARE @DelimIndex INT
    SET @ItemList = @InputString
    SET @DelimIndex = CHARINDEX(@Delimiter, @ItemList, 0)
    WHILE (@DelimIndex != 0)
    BEGIN
    SET @Item = SUBSTRING(@ItemList, 0, @DelimIndex)
    INSERT INTO @Items VALUES (@Item)
    -- Set @ItemList = @ItemList minus one less item
    SET @ItemList = SUBSTRING(@ItemList, @DelimIndex+1, LEN(@ItemList)-@DelimIndex)
    SET @DelimIndex = CHARINDEX(@Delimiter, @ItemList, 0)
    END -- End WHILE
    IF @Item IS NOT NULL -- At least one delimiter was encountered in @InputString
    BEGIN
    SET @Item = @ItemList
    INSERT INTO @Items VALUES (@Item)
    END
    -- No delimiters were encountered in @InputString, so just return @InputString
    ELSE INSERT INTO @Items VALUES (@InputString)
    RETURN
    END -- End Function
    GO
    Use the below script:
    create table Table1 (Product_Code varchar(50),Product_Desc varchar(10),sStart_date varchar(MAX))
    Insert into Table1 Values('P00002933','VITAMINE C','2005,2000,2011,2001,2002'),
    ('P00003087','BIOFENAC','2011,2009,2006,2007,2004,2005')
    Select Product_Code,Product_Desc ,MIN(Item) Minstart_date
    From Table1 A
    Cross apply Split(A.sStart_date,',') B
    Group by Product_Code,Product_Desc
    Drop table Table1

  • Column values convert to a single row...

    I have to return the column values to a single row seperated by comma.
    If any null values in the column just ignore it without leaving a comma.
    below is an eg. There are three values and two NULL values in the table
    SQL> select ID from temp_fa;
    ID
             1
             2
             3
             5
    6 rows selected.
    I am expecting an output as 1,2,3,5Please help

    There is always more than one way in the Oracle world ;)
    You can use TRIM, for example (same setup as your example):
    hoek&XE>  create table t as select level col  from dual connect by level <= 6;
    Tabel is aangemaakt.
    hoek&XE> update t set col = null where col in (1,3,5);
    3 rijen zijn bijgewerkt.
    hoek&XE> select * from t;
           COL
             2
             4
             6
    6 rijen zijn geselecteerd.
    hoek&XE> select ltrim(sys_connect_by_path(col, ','), ',') output
      2  from  ( select col
      3          ,      row_number() over (order by col) rn
      4          from   t
      5        )
      6  where connect_by_isleaf=1     
      7  start with rn=1
      8  connect by rn = prior rn+1;
    OUTPUT
    2,4,6,,,
    1 rij is geselecteerd.
    hoek&XE> select trim ( both ',' from sys_connect_by_path(col, ',')) output
      2  from  ( select col
      3          ,      row_number() over (order by col) rn
      4          from   t
      5        )
      6  where connect_by_isleaf=1     
      7  start with rn=1
      8  connect by rn = prior rn+1;
    OUTPUT
    2,4,6
    1 rij is geselecteerd.

Maybe you are looking for