Convert multiple rows to one row with multiple columns

Hi
i have a table Match_1 with 2 columns 'Source' and 'target'.One source can have multiple targets and that number could be anything
CREATE TABLE Match_1
Source CHAR(1),
Target CHAR(1)
INSERT INTO Match_1 VALUES ('A', 'B');
INSERT INTO Match_1 VALUES ('A', 'C');
INSERT INTO Match_1 VALUES ('A', 'D');
INSERT INTO Match_1 VALUES ('A', 'E');
INSERT INTO Match_1 VALUES ('V', 'X');
INSERT INTO Match_1 VALUES ('V', 'Y');
INSERT INTO Match_1 VALUES ('V', 'X');
INSERT INTO Match_1 VALUES ('V', 'W');
COMMIT;
i need to get my output in the below format
Source     target 1     target 2     target 3     target 4          target n
A     B          C          D               
V     X          Y          Z          W          
Could you please provide me the required SQL.
REgards
-Learnsequel

What is your database version (4 digit) ? also my example won't be generate columns for your information:
it will produce a result like that :
select source, listagg(target,',') within group (order by target)
  from  match_1
  group by source;
A     B,C,D,E
V     W,X,X,Yps: in previos post, I wrote "with" word wrong in sql.

Similar Messages

  • I wanted to display the multiple rows in one row but column should be diff

    Hi
    Could any body help me regarding this query how to write to get the multiple rows in one row.
    eg.
    i have one table tab1(eno number,ename varchar2,uid1 varchar2,uid2 varchar2,uid3 varchar4)
    but when i am runing the query I am getting multiple record against one eno number because of uid1,uid2,uid3
    suppose value of table is
    eno ename uid1 uid2 uid3
    1 a u1
    1 a u2
    1 a u3
    when i am quering it is coming same as above but I want in one row
    eno ename uid1 uid2 uid3
    1 a u1 u2 u3
    can any onle help me how to write the query for this requirement.
    thanks
    saif

    which is hard coded in my code? Here another approach, but fail for c as there is no information for the value of a column: does 1 in u1 means col 1, etc.
    /* Formatted on 2012/05/29 16:29 (Formatter Plus v4.8.8) */
    WITH t AS
         (SELECT 1 col1, 'a' col2, 'u1' col3
            FROM DUAL
          UNION ALL
          SELECT 1 col1, 'a' col2, 'u2' col3
            FROM DUAL
          UNION ALL
          SELECT 1 col1, 'a' col2, 'u3' col3
            FROM DUAL
          UNION ALL
          SELECT 1 col1, 'b' col2, 'u1' col3
            FROM DUAL
          UNION ALL
          SELECT 1 col1, 'b' col2, 'u3' col3
            FROM DUAL
          UNION ALL
          SELECT 1 col1, 'b' col2, 'u2' col3
            FROM DUAL
          UNION ALL
          SELECT 1 col1, 'c' col2, 'u1' col3
            FROM DUAL
          UNION ALL
          SELECT 1 col1, 'c' col2, 'u3' col3
            FROM DUAL)
    SELECT   xx.col1, xx.col2, MAX (DECODE (xx.rn, 1, col3)) AS uid1, MAX (DECODE (xx.rn, 2, col3)) AS uid2,
             MAX (DECODE (xx.rn, 3, col3)) AS uid3
        FROM (SELECT t.col1, t.col2, t.col3, ROW_NUMBER () OVER (PARTITION BY col1, col2 ORDER BY col3) rn
                FROM t) xx
    GROUP BY col1, col2;output:
    COL1     COL2     UID1     UID2     UID3
    1     a     u1     u2     u3
    1     b     u1     u2     u3
    1     c     u1     u3
    Edited by: ʃʃp on May 29, 2012 2:30 AM

  • How do i take one layer with multiple selections...

    how do i take one layer with multiple selections and make those selections their own layer?

    Yes sir. It w was really hard to explain. It is discontiguous segments that are separated by transparent areas. And I want those non transparent areas to be on their own layer. I have a photo shop file that has a bunch of buttons on them and they are on a transparent background. It is one layer. I want to select all the buttons and put them on their own layers. I can do this manually by selecting a button and cmd Just to a new layer, but when I have 200 buttons it is a daunting task.
    Sent by MailWise<http://www.mail-wise.com/installation/4> – Your emails, with style.

  • One order with multiple lines in OM is creating multiple invoices

    Application: Oracle 11i (11.5.3)
    Modules implemented: GL, OM, AR, AP, PO and CM
    Business Requirement:
    Our client would like to create Order consisting of multiple lines in Order Management.
    The Orders created in OM with multiple lines could be booked, picked, released and transferred
    over to Accounts Receivable. On transferring over the Orders from Order Management to Accounts
    Receivables using Auto Invoice process the Order should create ONE invoice with multiple lines.
    Moreover, for the multiple lines created on an invoice deferred revenue could be applied.
    ( eg. An order is placed for software and support. The support is to be invoiced all at once but revenue deferred to 1/12
    recognized each month as revenue is earned.)
    Right now we are getting two invoices. It is putting the deferred revenue item on a seperate invoice. Is this normal
    functionality? How can I get both on one invoice.
    thanks

    Hello Monique,
    Well you can have one invoice generated for an order with multiple lines. This is possible by changing some rules in Account Receivables. Use the grouping rules under setups->autoinvoice in AR. You can club your invoices based on any of the columns of ra_interface_lines_all. Hope this works for you.
    Arvind

  • How to have one provider with multiple portlets in JDev 11g

    Hi,
    I am trying to create Oracle PDK Portlets using JDeveloper 11g but for each portlet JDeveloper is creating a provider. As In JDeveloper 10.1.3.4 we can have one provider with multiple portlets in it. But JDev 11g creates provider for each portlet. How can we have one provider with multiple portlets in JDev 11g. Is it something changed in 11g version or am I doing it wrong. As the Help says we can have multiple portlets in one provider but when creating portlets it does not do that. Any help is appreciated.
    Thanks

    Hi,
    I am trying to create Oracle PDK Portlets using JDeveloper 11g but for each portlet JDeveloper is creating a provider. As In JDeveloper 10.1.3.4 we can have one provider with multiple portlets in it. But JDev 11g creates provider for each portlet. How can we have one provider with multiple portlets in JDev 11g. Is it something changed in 11g version or am I doing it wrong. As the Help says we can have multiple portlets in one provider but when creating portlets it does not do that. Any help is appreciated.
    Thanks

  • One Output with multiple communication types

    Hello,
    My requirement is to print the document as well as send an email to the customers from the same output.  Basically One output with multiple communication types ( PRINT  & EMAIL).  How to configure this in the output type configuration area? Please reply. Thanks

    This should be possible with the same output type,
    have the output type defined with multiple medium in NACE under processing routines. (say print out in one line & external send in another).
    have the condition record maintained appropriately for different customers with different medium.
    Note: if your access has customer, dont think you can maintain both 1 & 5 for the same access.
    if this functionality is required, i think you can acheive this by maintaining the output under different access, but this will not ensure the same condition type flowing into the document unless the earlier condition type goes to processed status.
    Thanks & Regards
    Ilango

  • Concatenate strings from more rows into one row.

    Hi,
    what's the name of that analytical function (or connect by) that
    would return strings from more rows as one row concatenated. i.e.:
    (I know this is possible using regular pipelined functions.)
    ROW1:   STR1
    ROW2:   STR2
    ROW3:   STR3
    select tadah().... from ...
    result:
    ROW1: STR1 STR2 STR3Thanks.

    Hi,
    Here's a basic example of SYS_CONNECT_BY_PATH.
    The query below produces one row of output per department, containing a list of the employees in that department, in alphabetioc order.
    WITH     got_rnum     AS
         SELECT     ename
         ,     deptno
         ,     ROW_NUMBER () OVER ( PARTITION BY  deptno
                                         ORDER BY          ename
                              ) AS rnum
         FROM     scott.emp
    --     WHERE     ...          -- Any filtering goes here
    SELECT     deptno
    ,     LTRIM ( SYS_CONNECT_BY_PATH ( ename
                                  , ','     -- Delimiter, must never occur in ename
               )          AS ename_list
    FROM     got_rnum
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     rnum          = 1
    CONNECT BY     rnum          = PRIOR rnum + 1
         AND     deptno          = PRIOR deptno
    ;Output:
    .   DEPTNO ENAME_LIST
            10 CLARK,KING,MILLER
            20 ADAMS,FORD,JONES,SCOTT,SMITH
            30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARDThe basic CONNECT BY query would produce one row per employee, for example:
    .   DEPTNO ENAME_LIST
            10 ,CLARK
            10 ,CLARK,KING
            10 ,CLARK,KING,MILLER
            20 ,ADAMS
            20 ,ADAMS,FORD
    ...The WHERE clause: <tt>WHERE CONNECT_BY_ISLEAF = 1</tt> means that we'll only see the last row for every department.
    SYS_CONNECT_BY_PATH (which is a row function, by the way, not an analytic fucntion) puts a delimiter (',' in the example above) before every item on the list, including the first one.
    The query above uses LTRIM to remove the delimiter at the very beginning.
    WM_COMCAT (or the equivalent user-defined STRAGG, which you can copy from AskTom) is much more convenient if order is not important.

  • How to combine many rows into one row

    Hi all,
    I have a question regarding to how to combine many rows into one row?
    My result set is like that:
    ITEM_NO NAME1
    11 abc
    11 cde
    11 fg
    Want to combine them into
    ITEM_NO NAME1
    11 abc;cde;fg
    would anybody can tell me how to do that? Thanks
    Ray

    You can check this --
    satyaki>
    satyaki>
    satyaki>create table t
      2  as
      3      select 11 ITEM_NO, 'abc' NAME1 from dual
      4      union all
      5      select 11 ITEM_NO, 'cde' NAME1 from dual
      6      union all
      7      select 11 ITEM_NO, 'fg' NAME1 from dual;
    Table created.
    satyaki>
    satyaki>
    satyaki>
    satyaki>set lin 10
    satyaki>
    satyaki>desc t;
    Name              Null?    Type
    ITEM_NO                    NUMBER
    NAME1                      VARCHAR2(3)
    satyaki>
    satyaki>
    satyaki>set lin 1000
    satyaki>
    satyaki>
    satyaki>
    satyaki>SELECT ITEM_NO,
      2         LTRIM(MAX(SYS_CONNECT_BY_PATH(NAME1,';'))
      3         KEEP (DENSE_RANK LAST ORDER BY curr),';') AS NAME1_DET
      4  FROM   (SELECT ITEM_NO,
      5                 NAME1,
      6                 ROW_NUMBER() OVER (PARTITION BY ITEM_NO ORDER BY NAME1) AS curr,
      7                 ROW_NUMBER() OVER (PARTITION BY ITEM_NO ORDER BY NAME1) -1 AS prev
      8          FROM   t)
      9  GROUP BY ITEM_NO
    10  CONNECT BY prev = PRIOR curr AND ITEM_NO = PRIOR ITEM_NO
    11  START WITH curr = 1;
       ITEM_NO  NAME1_DET
            11  abc;cde;fgRegards.
    Satyaki De.

  • Merging rows into one row but into SEPARATE Columns

    Hello Gurus,
    I have searched alot on OTN and many other places, but no where I could get the solution of how can we merge rows into one row but separate column. For example
    Consider the below scenario
    "DEPARTMENT", "EMP","NAME","SUBJECT"
    "Electronics","1","Sam","LIC"
    "Electronics","2","Pam","VLSI"
    "Electronics","3","Tom","C"
    "Mech","1","Abu","Thermo"
    "Mech","4","Lina","Machines"Now, I need the output like
    Based on Department as Group By Clause
    "DEPARTMENT", "EMP1","NAME1","SUBJECT1","EMP2","NAME2","SUBJECT2","EMP3","NAME3","SUBJECT3"
    "Electronics","1","Sam","LIC","2","Pam","VLSI","3","Tom","C"
    "Mech","1","Abu","Thermo","4","Lina","Machines"
    The row data to be loaded into separate columns. Name of the column is not an issue... can be anythingIn all the forums which I went through I could find them loading into a single column, but not into respective separate columns.
    Any help would be much appreciated.
    Thanks

    848265 wrote:
    Frank,
    I saw your name nearly n number of times, as I went through many forums today... And the link which you have just posted, I went through it today afternoon.
    Could you please explain this bit taken from your dynamic pivot post.
    SELECT     DISTINCT
         ',     COUNT (CASE WHEN job = '''
    ||     job
    ||     ''' '     AS txt1
    ,     'THEN 1 END)     AS '
    ||     job
    ||     '_CNT'     AS txt2
    FROM     scott.emp
    ORDER BY     txt1;Many Thanks.You only need that when you need column aliases based on the actual data (and you explicitly said you don't need that) or when can't put an upper bound on the number of columns to be displayed. If that doesn't apply to this problem, then don't use any kind of dynamic SQL (like the code above); it makes the job much more difficult, less efficient and less robust.
    Here's what the code above is doing.
    If you were hard-coding a query that showed the number of people in each job, and you knew that the possible jobs were 'ANALYST', 'CLERK' and 'MANAGER', then you might hard-code a query like this:
    SELECT    deptno
    ,       COUNT (CASE WHEN job = 'ANALYST'  THEN 1 END)     AS analyst
    ,       COUNT (CASE WHEN job = 'CLERK'    THEN 1 END)     AS clerk
    ,       COUNT (CASE WHEN job = 'MANAGER'  THEN 1 END)     AS manager
    FROM       scott.emp
    GROUP BY  deptno
    ;If the jobs had different names, or if there were not 3 different jobs, then you would have to change the lines in the SELECT clause that start with ", COUNT ( CASE ...".
    The code you posted is from an example of dynamic SQL, where you first run a Preliminary Query . (What you posted above is, in fact, the complete preliminary query.) The output of that preliminary query is exactly the variable part of the real query, such as:
    ,       COUNT (CASE WHEN job = 'ANALYST'  THEN 1 END)     AS analyst
    ,       COUNT (CASE WHEN job = 'CLERK'    THEN 1 END)     AS clerk
    ,       COUNT (CASE WHEN job = 'MANAGER'  THEN 1 END)     AS managerYou then use this output as part of your main query. In other words, you can write something today that will generate exacrly as many columns as you need next year, with names from the data as it is next year. How? because you're not writing the full query today. The variable part will be written by the preliminary query when it runs next year.

  • Can i install itunes multiple times on one computer for multiple users?

    Can i install itunes multiple times on one computer for multiple users?

    Like most applications you only need to install it once for it to be available to all users. (That said it is possible to install an application and only make it available to the current user, but that's rarely needed.)
    tt2

  • Error inserting a row into a table with identity column using cfgrid on change

    I got an error on trying to insert a row into a table with identity column using cfgrid on change see below
    also i would like to use cfstoreproc instead of cfquery but which argument i need to pass and how to use it usually i use stored procedure
    update table (xxx,xxx,xxx)
    values (uu,uuu,uu)
         My component
    <!--- Edit a Media Type  --->
        <cffunction name="cfn_MediaType_Update" access="remote">
            <cfargument name="gridaction" type="string" required="yes">
            <cfargument name="gridrow" type="struct" required="yes">
            <cfargument name="gridchanged" type="struct" required="yes">
            <!--- Local variables --->
            <cfset var colname="">
            <cfset var value="">
            <!--- Process gridaction --->
            <cfswitch expression="#ARGUMENTS.gridaction#">
                <!--- Process updates --->
                <cfcase value="U">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                    <cfquery datasource="#application.dsn#">
                    UPDATE SP.MediaType
                    SET #colname# = '#value#'
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <!--- Process deletes --->
                <cfcase value="D">
                    <!--- Perform actual delete --->
                    <cfquery datasource="#application.dsn#">
                    update SP.MediaType
                    set Deleted=1
                    WHERE MediaTypeID = #ARGUMENTS.gridrow.MediaTypeID#
                    </cfquery>
                </cfcase>
                <cfcase value="I">
                    <!--- Get column name and value --->
                    <cfset colname=StructKeyList(ARGUMENTS.gridchanged)>
                    <cfset value=ARGUMENTS.gridchanged[colname]>
                    <!--- Perform actual update --->
                   <cfquery datasource="#application.dsn#">
                    insert into  SP.MediaType (#colname#)
                    Values ('#value#')              
                    </cfquery>
                </cfcase>
            </cfswitch>
        </cffunction>
    my table
    mediatype:
    mediatypeid primary key,identity
    mediatypename
    my code is
    <cfform method="post" name="GridExampleForm">
            <cfgrid format="html" name="grid_Tables2" pagesize="3"  selectmode="edit" width="800px" 
            delete="yes"
            insert="yes"
                  bind="cfc:sp3.testing.MediaType.cfn_MediaType_All
                                                                ({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
                  onchange="cfc:sp3.testing.MediaType.cfn_MediaType_Update({cfgridaction},
                                                {cfgridrow},
                                                {cfgridchanged})">
                <cfgridcolumn name="MediaTypeID" header="ID"  display="no"/>
                <cfgridcolumn name="MediaTypeName" header="Media Type" />
            </cfgrid>
    </cfform>
    on insert I get the following error message ajax logging error message
    http: Error invoking xxxxxxx/MediaType.cfc : Element '' is undefined in a CFML structure referenced as part of an expression.
    {"gridaction":"I","gridrow":{"MEDIATYPEID":"","MEDIATYPENAME":"uuuuuu","CFGRIDROWINDEX":4} ,"gridchanged":{}}
    Thanks

    Is this with the Travel database or another database?
    If it's another database then make sure your columns
    allow nulls. To check this in the Server Navigator, expand
    your DataSource down to the column.
    Select the column and view the Is Nullable property
    in the Property Sheet
    If still no luck, check out a tutorial, like Performing Inserts, ...
    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/index.jsp
    John

  • I have 3 drop down boxes in my report done SQL SSRS .. I want t to put them in the same row (just one row) ..how can I do it.?

    I have 3 drop down boxes in my report done SQL SSRS .. I want t to put them in the same row (just one row) ..how can I do it.?

    Hi Sashi123,
    Just as Ivan said, we do not have the ability to change the Report Manager in this way. Because we can’t change the parameters locations as this is not supported to write expressions for the location of parameters.
    While we can build a custom application in Visual Studio that we can get it through codes after deploying the report, then through URL we can get it by customization.
    Hope this helps.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • A way to roll up rows into one row

    Is there a way to "roll up" a set number of rows into one row? I would like to have a row that can be expanded into several rows by clicking a plus sign or something similar. Anyway to do this?
    Regards,
    Mark

    Mark,
    Sorry, it didn't occur to me that you meant "hiding". It sounds like you already know how to hide and unhide but unfortunately there are no shortcuts. I agree that it would be nice to have a way to unhide a selected row or column and if my memory serves me I submitted a request for this feature some months ago. May I suggest that you also go to Main Menu > Numbers > Provide Numbers Feedback.
    The more requests for features they receive the better the chance for getting them in future updates. Best wishes,
    pw

  • Splitting multiple rows onto one row with different fields

    Hi all,
    I have a table. One Course_Code have multiple section_codes i.e. ("NUM" column does not relate to sectype its just an order!)
    Code--------num----Sec_code---Sectype---DESC----------------WEIGHT
    1603--------1-------7427-----------C------------Coursework--------     50
    1603--------2-------7428-----------E------------     Exam----------------     50
    When I query this table i want to be able to see the coursework, exam split on the same row. i.e.
    Code-----Coursework---------Exam
    1603-----C=50------------------E=50
    any help would be great

    Hi,
    "Splitting" means taking an item (such s a string like 'C=50') and diviiding it into smal;ler items (such as the sub-strings 'C' and '50'). Are you really trying to split something, or are you trying to do just the opposite (e.g., combine smaller strings into a bigger string)?
    I think what you're looking for is a Pivot . Like so many other things, exactly how to do it depends on your version of Oracle and your requirements.
    Here's one way:
    SELECT       code
    ,       MIN (CASE WHEN descr = 'Coursework' THEN sectype END)
           ||  '='
           MIN (CASE WHEN descr = 'Coursework' THEN weight  END)     AS coursework
    ,       MIN (CASE WHEN descr = 'Exam'       THEN sectype END)
           ||  '='
           MIN (CASE WHEN descr = 'Exam'           THEN weight  END)     AS exam
    FROM       table_x
    GROUP BY  code
    ;This will work in Oracle 8.1 and higher. Starting in Oracle 11.1, you could also use the SELECT ... PIVOT feature.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Multiple record in one row..

    Hi experts,
    I want to merge multiple row from same table into one row... is it possible? if so then how??
    Regards,
    SKP

    Sure, it's possible
    create table scott.a
    as
    select 1 a, 2 b from dual     
    union all
    select 3 a, 4 b from dual     
    create table scott.b
    (a number, b number, c number, d number)
    insert into scott.b
    select a1.a,a1.b,a2.a,a2.b from scott.a a1, scott.a a2
    where a1.a = 1 and a2.a = 3
    P.S. Sorry, at first misunderstood the task
    Message was edited by:
    Dmytro Dekhtyaryuk

Maybe you are looking for

  • Preview and Texteditor open multiple files

    Preview and Texteditor often open multiple files when I only clicked a single file. It seems to open one or more previously opened files at the same time. Is this a bug, or can I disable this behaviour somewhere?

  • How do i back up music from Iphone 4 in to Icloud

    How do I back up the songs from Iphone 4 to I cloud ?

  • BB pearl 8100 downloads

    I just upgraded the software to 4.5 and when I go into BB app world to download a new (free) game I get the following error message  "An error has occurred communicating with the BlackBerry App World Client".  Can anyone tell me why?  Or what I have

  • IMac, actually is any mac worth it?  -doesn't i in iMac stand for Internet?

    Somewhere after the 10.5.2 updates, things started going south. I should also include I'm on ATT Yahoo DSL 3/512 with a 2Wire 2701 HGB. Also tested on a Ambit (single line, Natted but not routed) Cable modem (would not acquire DHCP). using just ether

  • Problems with Compaq Presario CQ61

    I have a Presario CQ61 and recently updated the iTunes software installed. Everything worked fine until I went to shut down the computer. While waiting for the windows menu to load it crashed, since then it hasn't worked (some 5 days).  When I turn i