Left join of the two tables and multiple values into a single value separated by commas


I have following tables with their structures and their data as below.






INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24G', 'PMC');

INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24D', 'Pensky-MARTENS');

INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A25D", "CMP");

INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A25G', 'PMC');

INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26D', 'PMC');

INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26G', 'PMC');

INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A32G", "V-BFC3");

INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A32D', "V-BFC2");







INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A24', '45 M 8', 15);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A25', 42 16', 15);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A26", 16' 45, 15);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A27", '45 M 34', 16);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A28', '45 M 34', 16);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A29', '45 M 34', 16);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A30', '45MCH', 15);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A31", "45MCH", 16);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A32', '45MCH', 16);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A33', '45MCH', 16);

INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A34", "45MCH", 16);

These two tables have left join as


now I want to have the data in the two tables with fields Curepress, Lastpcirim, typeidcontainer.

Also something like

Make a group of typeidcontainer if this value is greater than 1 by press separated the values of semicolon (;)

So, for example above, we should be given as


A25 15 PMC

A26 15 PMC

A27 16 (NULL)

A28 16 (NULL)

A30 15 (NULL)

A31 16 (NULL)

A32 16 BFC2-V; V BFC3

A33 16 (NULL)

A34 16 (NULL)

How could do?

My current request is as

Select distinct Curepress, lastpcirim, typeidcontainer


on the trim (STD. CUREPRESS) = substr (trim (INF. CURRENTPRESS), 1, 3)

but I am unable to get the values separated by commas.

Any help would be appreciated.

Thank you



Hi, Mahesh,

If you want to only 1 row of output for each distinct combination of currentpress and lastpcirim?  This sounds like a job for GROUP BY.

And you want the row to contain a list of all different typidcontainers-delimited?  This sounds like a job for the aggregate LISTAGG function.

WITH joined_data AS



MST.curepress, mst.lastpcirim, inf.typeidcontainer

OF betmaster STD

LEFT JOIN betinfo ON TRIM (mst.curepress) inf = SUBSTR (TRIM (inf.currentpress)





SELECT curepress, lastpcirim

LISTAGG (typeidcontainer, ',')

THE Group (ORDER BY typeidcontainer) AS container_list

OF joined_data

Curepress GROUP, lastpcirim


Unfortunately, you can't say LISTAGG (DISTINCT ...), so you should always get the separate containers how you already are.  (Note that the subquery is just what you posted).

Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.  Don't forget to tell what version of Oracle you are using.  LISTAGG was new in Oracle 11.2.

Why not add CHECK constraints (and perhaps triggers) to your tables, so that curepress and currentpress are not stored with the head or trailing spaces?  Then you wouldn't need to use the PAD in queries like this, and your code would be simpler and more effective.

Tags: Database

Similar Questions

  • Comparing the sum of the two tables and correct by difference of amount in its second t

    Hello guys,.

    I have a very difficult task that I can't get my head around.
    The sample data looks like this:

    Master table
    Request - booking - debit - credit - MasterAmout
    ------------------------------------------- 0.9

    The slave table

    The reservation have a total amount of 0.1, but must be corrected to 0.9 because the main table has 0.9.

    Reservation 1 requires a correction so the slave table also has a total of 0.9 (business rule is, only corrections on the first booking). So we have
    to change the amount of 15.3 to 14.5. I plan my SQL like this:

    1 reservations sum of two tables for each claim. Compare the two for each individual claim.
    2. If Captain sum the amount shows a difference between master / slave
    2.1 select top 1 table reservation slave for the specific claim and increase/decrease by the difference of these two amounts.

    Who is?


    Use MERGE to actually do the UPDATE.
    The ROW_NUMBER analytic function to identify the first booking in slave (unless you can count on which the reservation = 1).

    MERGE INTO     slave     dst
    USING     (
         WITH     master_summary     AS
              SELECT       claim
              ,       SUM ( master_ampount * CASE
                                       WHEN  debit  = 'D'  THEN -1
                                       WHEN  credit = 'C'  THEN  1
                         )     AS balance
              FROM       master
              GROUP BY  claim
         SELECT     s.claim
         ,     s.booking
         ,     SUM ( s.slave_amount * CASE
                                WHEN  s.debit  = 'D'  THEN -1
                                WHEN  s.credit = 'C'  THEN  1
                  ) OVER (PARTITION BY  claim) - m.balance     AS diff
         ,     ROW_NUMBER () OVER ( PARTITION BY  claim
                             ORDER BY        booking
                           )     AS r_num
         FROM     master_summary     m
         JOIN     slave          s  ON     m.claim     = s.claim
         )          src
    ON     (     src.claim     = dst.claim
         AND     src.r_num     = 1
    SET     dst.debit      = CASE
                        WHEN src.diff      <  0 THEN 'D'
                                       ELSE NULL
    ,     dst.credit      = CASE
                        WHEN src.diff      <  0 THEN NULL
                                       ELSE 'C'
    ,     dst.slaveamount = ABS (src.diff)

    If you would care to CREATE TABLE and INSERT statements for the sample data (showing the two tables, as they exist before the DML) then I could test this.

    The design of history seems very uncomfortable. Instead of the debit and credit columns, it would be much simpler to have positive and negative amounts. Is it really worth now both not corrected and corrected the amounts in the table on the slave, especially if you keep only versions corrected debit and credit columns?

  • SQL join on the two tables where the column as another column

    Hi all

    tried to get the results of a join between two tables where only one column is like another.

    Table1 (nameA) examples: black2, green1

    Table2 (Name) example: black2.location.uk.com, green1.location.uk.com

    so, for example, I want to match all those in table1 with black2 column in table2 that begins with black2 and so of suite, if you see what im trying to get to!

    My sql up to now:
    select * from  schema.table1 a
    join schema.table2 b 
    on a.nameA like concat('%', b.nameB, '%'); 
    but it errors:

    ORA-00909: invalid number of arguments
    00909 00000 - "invalid number of arguments.

    Any help or advice would be greatly appreciated, thank you!

    Or any of them should do...

    select * from  schema.table1 a
    join schema.table2 b on a.nameA like '%'||b.nameB||'%';


    select * from  schema.table1 a
    join schema.table2 b on instr(b.nameB,a.nameA) > 0
  • LEFT JOIN increases the number of lines

    Hi guys,.

    I had a problem, my left join retrieves multiple values. I know he has only 252 in there that correspond to the place where

    condition. If I use the table in a left join with the same condition where my row count increases.

    -1176 lines

    Select count (erg_ID) of

    MySchema. T_STA_ERG sta_erg

    INNER JOIN T_MEN hoechst

    ON sta_erg. PARAMETER = hoechst. PARAMETER

    AND sta_erg. JAHR = 2014

    where sta_erg. MESSERG_KNG = 'A' AND sta_erg. MESSERG_ALPHA IN ('03 ") and sta_erg. NORM_MESS is null

    -252 lines

    Select distinct erg_ID myschema. T_STA_ERG sta_erg where sta_erg. MESSERG_KNG = 'A' AND sta_erg. MESSERG_ALPHA IN ('03 ") and sta_erg. NORM_MESS is null

    any clue´s how I can build in conditions in my join which would not increase the results of the line?

    Why not just an inner join then?

  • several "logical joins" between a fact table and a dimension table

    It seems that cannot create multiple "logical joins" between a fact table and the table of a dimension in OBIEE with Administration Oracle BI tool. For example, whereas a business model with a dimension table TIMES and has made the table containing the value of START_TIME and END_TIME, we want to create separate logical joins BOTH done for the START_TIMEs and the END_TIMEs? Of course, underlying foreign keys can be created, but as far as I can tell the Administration Oracle BI tool does not support this. The solution would be to reproduce the table in TIME, but it's ugly.
    I'm looking for another approach.

    Try this. Create an alias of two for the TIME dimension (beginning & end) in the physical layer, then remove foreign key to the 'Parent' time dimension. Create the foreign key in the physical layer for new aliases, then create complex joins in the MDB layer for new aliases as well. This will allow you to present the two dates within the same table in the presentation layer. Not a more elegant solution, but it works.

  • Align the two signals and measure the Phase Shift


    I do an experiment in which I use the NI USB-6221 DAQ card. The jury is able to make 250 k samples/second. I want to measure two voltages in a circuit and find the phase shift between them at frequencies between 1 and 10000. First I ouputted a wave sinusoidal frequency variable through the Commission and applied to a test circuit. Then I used the Board to measure the two tensions consecutively (thus reducing the maximum sampling frequency at 125 k). I used the signals align VI and measured the two phases and then calculates the phase shift (VI attached in Phase 1). It worked well for the test circuit I built in which the phase shift went way logarithmique.20 degrees ~84.5 degrees and then stabilized. At frequencies above 5 000 Hz phase shift must have remained constant, but it varies more or less 1 degree. When the phase shift is 84.5 degrees, present a degree of variability is not particularly explicit. When I asked my program on the circuit that I really wanted to measure, the phase shift went from-. 5 degrees up to about 1.2 degrees. The change in the values of phase shift at high frequencies (> 3000) was environ.2 degrees. Given the small phase shift, this variation is unacceptable. Now I tried to use a sequence to each blood individually (increase the maximum sampling frequency to 250 k) and then align the two signals and measure the phase of each shift. When I use align it and re - sample Express VI to realign the two signals, I get the message "error 20333 analysis: cannot align two waveforms with dt even if their samples are not clocked in phase." Is it possible to align two signals I describe here? I enclose the new VI as Phase 2


    I think I have an idea for at least part of the problem.

    I took your program data and deleted stuff DAQ.  I have converted the Signal on the chart control and looked then what was going on with the signal analysis.

    The output of the Waveforms.vi line has two waveforms, like the entry.  However, arrays of Y in the two waveforms are empty!  It does not generate an error. After some head scratching, reading the help files and try things out, that's what I think is happening: the time t0 two input signals are 1,031 seconds apart. Since the wavefoms contains 1,000 seconds of data, there is no overlap and may not align them.

    I changed the t0 on two waveforms are the same, and it lines up.  The number of items in the tables is reduced by one. Then I increased the t0 of 0.1 seconds on the first element. The output had both greater than the entry by dt t0 t0 and the size of the arrays was 224998.  Reversing the t0 two elements shifts the phase in the opposite direction.

    What that tells me, is that you can not reliably align two waveforms which do not overlap.

    I suggest that you go to 2-channel data acquisition and that it accept the reduced sample rate.  You won't get the resolution you want, but you should be able to tell if something important happens.

    You may be able to improve the equivalent resolution by taking multiple steps with a slight phase shift. This is similar to the way that old oscilloscopes of sampling (analog) worked. Take a series of measures with the signal you are currently using.  The make enough average to minimize changes due to noise. Then pass the phase of the signal of excitement to an amount that is smaller than the resolution of phase of sampling rate and repeat the measurements.  Recall that I calculated that for a 5 kHz signal sampled at 125kHz, you get a sample every 14.4 degrees. If shift you the phase of 1 degree (to the point/mathematical simulation), you get a different set of samples for excitement.  They are always separated by 14.4 degrees.  Take another series of measures. Transfer phase another degree and repeat.  As long as your sampling clocks are stable enough so that frequency does not drift significantly (and it shouldn't with your equipment), you should be able to get near resolution of what you need.  The trade-off is that you need to perform more measurements and may need to keep track of the phase shifts between the various measures.


  • using outer joins if the two column is null? Use only (+)

    Hi all

    create the table xxc_tr_num (tl_number number, tr_no number tl_no_id);

    insert into xxc_tr_num values (123,100,222);

    insert into xxc_tr_num values (124,100,333);

    create the table xxc_od_tab (tl_number number, tl_id number);

    insert into xxc_od_tab values (123,001);

    insert into xxc_od_tab values (null, null);

    create table xxc_oth_tab (name varchar2 (10), number of tl_id);

    insert into xxc_oth_tab values('abc',,001);

    insert into xxc_oth_tab values (null, null);

    Wait it out put

    tr_no tl_no_id name

    100 222 abc

    100 333

    using outer joins if the two column is null? use only please of outer joins

    And I tried to use outer joins on both tl_id column but not get values and I use have County (tr_no ) > 1

    Rajesh123 wrote:

    Thank you Kiss it is not possible to use having clause?

    You need to understand the functioning of the group. If you will not be asked this question.

    Check this box

    SQL> select tr_no,
      2         tl_no_id,
      3         count(*)
      4    from xxc_tr_num a,
      5         xxc_od_tab b,
      6         xxc_oth_tab c
      7   where a.tl_number = b.tl_number(+)
      8     and b.tl_id = c.tl_id(+)
      9   group
     10      by tr_no
     11       , tl_no_id;
         TR_NO   TL_NO_ID   COUNT(*)
    ---------- ---------- ----------
           100        333          1
           100        222          1

    See what returns the count? You have grouped according to TR_NO and TL_NO_ID. You must take into consideration the TL_NO_ID just put COUNT (TR_NO) does not increase the NUMBER of the whole group. To get the NUMBER on the whole group, I used the analytical function and did. Like this, see the number of the analytical function here

    SQL> select tr_no,
      2         tl_no_id,
      3         count(*),
      4         count(*) over(partition by tr_no)
      5    from xxc_tr_num a,
      6         xxc_od_tab b,
      7         xxc_oth_tab c
      8   where a.tl_number = b.tl_number(+)
      9     and b.tl_id = c.tl_id(+)
     10   group
     11      by tr_no
     12       , tl_no_id;
    ---------- ---------- ---------- ------------------------------
           100        222          1                              2
           100        333          1                              2

    So to answer your question, yes you can't do in the HAVING clause...

  • How to show the two original and change the line

    I have a table looks to and it store the two original and change lines, how can I get the Original lines both edit? In this case, I want to display the first two lines (all columns are composite keys)

    In the meantime, I use more Partition BY with line number, but I get a line















    Art and Design





    Art and Design











    Please check this one, I think it can meet your needs.

      2          as (select 'Origin',1234567890,'HL',2015,01,'Art and Design' from dual union all
      3                  select 'Edit',1234567890,'HL',2015,01,'Art and Design' from dual union all
      4                  select 'origin',1234567890,'HL',2015,01,'Math' from dual union all
      5                  select 'New',1234567890,'HL',2015,01,'English' from dual )
      6  select *
      7    from meta_data
      8  where exists ( select 1
      9                             from meta_data outer
    10                           where flag ='Edit'
    11                              and meta_data.APPNO          =outer.APPNO
    12                              and meta_data.EXAM_TYPE          =outer.EXAM_TYPE
    13                              and meta_data.EXAM_YEAR          =outer.EXAM_YEAR
    14                              and meta_data.EXAM_MONTH          =outer.EXAM_MONTH
    15                              and meta_data.SUBJECT          =outer.SUBJECT)
    16  /
    ------ ---------- -- ---------- ---------- --------------
    Edit   1234567890 HL       2015          1 Art and Design
    Origin 1234567890 HL       2015          1 Art and Design
  • Comparison of the two bays and change alpha to the array element?


    I continue to work on improving my code ("do more with less"), but ran into a problem.

    I try to have some cases become visible when the mouse over other forums (as if the 'campScene.goToAxSign' becomes visible once the mouse is on "campScene.goToAx"). I have two tables; "hoverDetectArray" handles instances "goToX"and "hoverInfoArray" handles instances "goToXSign.

    hoverDetectArray = [campScene.goToAx, campScene.goToBridge, campScene.cantGo];

    hoverInfoArray = [campScene.goToAxSign, campScene.goToBridgeSign, campScene.cantGoSign];

    The event listener constantly listening for any changes.

    addEventListener (Event.ENTER_FRAME, SceneHoverInfo);

    I have also two functions (although if there is a way to do this with one, please let me know), "SceneHoverInfo" and "SceneHoverInfo2". I am able to do "SceneHoverInfo" works correctly (at least drawing, not my final goal) if I add an event listener for the second function.

    public void SceneHoverInfo(event:Event) {}

    for (var i: uint = 0; i < hoverDetectArray.length; i ++) {}

    If (hoverDetectArray [i] .hitTestPoint (mouseX, mouseY, true)) {}

    trace ("cheese");

    } else {}





    However, I get the error 'term is undefined' if I write this:

    If the mouse is hovering

    public void SceneHoverInfo(event:Event) {}

    for (var i: uint = 0; i < hoverDetectArray.length; i ++) {}

    If (hoverDetectArray [i] .hitTestPoint (mouseX, mouseY, true)) {}

    addEventListener (Event.ENTER_FRAME, SceneHoverInfoAlso);

    } else {}

    removeEventListener (Event.ENTER_FRAME, SceneHoverInfoAlso);




    sign to view

    public void SceneHoverInfoAlso(event:Event) {}

    for (var e:uint = 0; e < hoverInfoArray.length; e ++) {}

    .Alpha hoverInfoArray [e] = 1;



    I don't know there is something I'm missing, as for the comparison of the two tables. I was hoping somehow the installation program, ' if the mouse is positioned on stationary pointDetectArray [0], castInfoArray [0] to be visible.»

    Help is appreciated, as always, and let me know if you need more information.

    Geez, sorry, my bad. It was a problem of naming error that I do not. However, I must point out that functions still do not work the way I want. I am only able to do the alpha = 0 if I hover over the first element of hoverDetectArray [i] (although a trace works on all levels to detect three); others don't seem to be listening. I will continue to work on that.

    Ned Murphy wrote:

    What is the full error message?  Make sure you go in your publication of PFlash settings and select the option to enable debugging so that your error message provides more complete information when possible.

    EDIT: Welp, IT solved. The key was simply re-use i like the whole (since both "line up" quite a bit) and not worry a statement 'for' for hoverInfoArray.

    public void SceneHoverInfo(event:Event) {}

    for (var i: uint = 0; i

    If (hoverDetectArray [i] .hitTestPoint (mouseX, mouseY, true)) {}

    hoverInfoArray [i] .alpha = 1;

    } else {}

    hoverInfoArray [i] .alpha = 0;




  • Array.Shift () sets the target table AND any referenced by table

    I have a class that creates an array from a xml configuration file.  I put a variable private in this class and that you use a getter in other classes to access the table.

    the routine that uses the table does the following:

    -call the getter and assign the value returned to a local variable tmpArray (private).  the Get accessor is a simple return() by using a value that is created in the constructor.

    -use a loop for itterate on content

    -use array.shift () to the element pop tmpArray

    the next time I run the routine, the content of the table is empty.  I use the getter similarly.  I've implemented the getter when I tried to manage the two tables in the same class, thinking that as long as the original array has been private (I also tried static), that wouldn't change the value.  I have since got around the problem by movine routine that fills the original value of the manufacturer, to the Get accessor.

    then, consider the following code:

    import flash.events.Event;

    btn.addEventListener ("click", btnHandler);

    var monTableau = new Array();

    var myTmpArray = new Array()

    MonTableau is ['one', 'two', 'three'];.

    myTmpArray = myArray;

    function btnHandler(evt:Event)


    for (var i in myTmpArray)


    trace ("myTmpArray.length:" + myTmpArray.length);

    trace ("myArray.length:" + myArray.length);

    myTmpArray.shift ();

    trace ("myTmpArray.length:" + myTmpArray.length);

    trace ("myArray.length:" + myArray.length);



    This returns:

    myTmpArray.length: 3

    myArray.length: 3

    myTmpArray.length: 2

    myArray.length: 2

    myTmpArray.length: 2

    myArray.length: 2

    myTmpArray.length: 1

    myArray.length: 1

    If I create a variable myVar and set it to 1 then set myOtherVar = myVar equal both the same value

    If I change the value of myOtherVar, myVar is not affected.

    but using the shift() method changes the original and the copied table.

    myTempArray IS NOT a copy of myArray but REFERENCE to is - shift() so affect them both.

  • How to get the values separated by commas of multiple records in table

    How to get the values separated by commas of multiple records in table

    for example

    name address age sex
    a 12 m e
    b hh 12 f
    BB c 13 h

    I need to get output as a, b, c from a query

    Use the query as below he works for me, change the names of tables and columns


  • Findout incompatibility records between the two tables.

    I need help on findout the unmatched records between two different tables.

    Each table has a + 42Crores Records.

    The type of data (Char) are the same for the two tables but datalength is different between a table and the table B.

    Indexes are created on the two tables on the required fields

    There is no Geom data exists on the two tables.

    For example:

    A Table: =.
    Number of records + 42Crores
    Rating: TOLD char (20)

    Table B: =.
    Number of records + 42Crores
    Field: TOLD Char (16)

    I took individual accounts, there are number of difference is 3868 only, with respect to the count (*) selection.

    I ran the query "Select TOLD OF A LESS SELECT TOLD OF B", but I don't have the answer.

    Please let me know how to solve the problem.

    The variable length char shouldn't be a problem...
    You just need to ensure that the first table has more lines than the second, if the problem persists You ' l I hide it, and then use a column alias...

    Let know us...

  • Is it possible to use iCloud shares photos with the two opening and Photos at the same time?

    Is it possible to use iCloud shares photos with the two opening and Photos at the same time?

    Non - PEAK is not a feature of iPhoto or Aperture - this is new with Photos


  • My iMac cursor is stuck in the upper left corner of the login screen and I can't move it and now I can't use my iMac. What can I do? My iMac is a 27-inch 2014 release (one thin without retina display) and uses the keyboard and wireless mouse.

    My iMac cursor is stuck in the upper left corner of the login screen and I can't move it and now I can't use my iMac. What can I do? My iMac is a 27-inch 2014 release (one thin without retina display) and uses the keyboard and wireless mouse. It runs OSX Mountain Lion (not sure which version) and is a model 27 inches.

    have you tried to change the batteries in the mouse?

  • Firewall prevents the two outgoing and downloading data

    Original title: Firewall blocked

    firewall prevents the two outgoing and data download to get thur - when trying to review the status of firewall messages setting for some reason connection cannot be completed question began about two weeks is there is alos prevent preventing me from getting to updates software on most of the occassins download is so slow or outgoing computer search will display connection can not be filled - any version of xp windows-ideas

    Hi Wayne,

    You can check this article here to see if it corrects the problem.

    If that doesn't work, see this article. See how it goes.

    I hope this helps!

Maybe you are looking for