Add rows from another table

Hi ,
I have a table with 20 records and 10 columns.I want to add columns from another table with out cross join.

As others have said, you need to have some sort of join condition otherwise it is a cross join.
SQL> ed
Wrote file afiedt.buf
  1  with T1 as (select 'e' as c1, 2 as c2 from dual union all
  2              select 'd', 3 from dual)
  3      ,T2 as (select 'x' as c3, 5 as c4 from dual union all
  4              select 'y', 6 from dual union all
  5              select 'z', 2 from dual)
  6  --
  7  select T2.c3, T2.c4, T1.c1, T1.c2
  8  FROM (select c1, c2, row_number() over (order by c1) as rn from T1) T1
  9       FULL OUTER JOIN
10       (select c3, c4, row_number() over (order by c3) as rn from T2) T2
11*      ON (T1.rn = T2.rn)
SQL> /
C         C4 C         C2
x          5 d          3
y          6 e          2
z          2
SQL>This example assigns a row number to each row within each table and then joins using that row number.
(I've assumed the row number should be generated based on the order of the first column of each table, but you can change that as required).
What is the point of your requirement?

Similar Messages

  • Insert missing rows from another table

    Hi
    I need to insert rows from another table if there is gaps in my transaction table. For each ärendenr there should be 5 Id status rows (1-5). Except for the fact that the inserted rows never should have higher IdStatus number then the highest value from
    the transaction for each Ärendenr. See my example below that illustrates my transaction table, Stages master and the desired result.
    Is there some t sql code that could handle this problem?
    Best regards
    Arne
    So far i have tried to solve this with the code below but it doesnt work.
    I have copied the transaction file information to the TempLogTransTimes
    and then insert into LogTransTimes
    IF OBJECT_ID('dbo.TempLogTransTimes', 'U') IS NOT NULL --Här raderas den tillfälliga tabellen
    DROP TABLE dbo.TempLogTransTimes;
    SELECT *
    INTO TempLogTransTimes
    FROM LogTransTimes
    DECLARE @TopÄrende INT
    WHILE EXISTS(SELECT * FROM TempLogTransTimes)
    BEGIN
    SET @TopÄrende = (SELECT TOP(1) Ärendenr FROM TempLogTransTimes ORDER BY Ärendenr)
    INSERT INTO LogTransTimes(Ärendenr, IdStatus, StatusNamn, SourceId)
    SELECT @TopÄrende, SM.IdStatus, SM.StatusNamn, 'Beräkning'
    FROM Statusmall SM
    FULL JOIN TempLogTransTimes LT ON SM.IdStatus = LT.IdStatus
    WHERE LT.IdStatus IS NULL
    DELETE TempLogTransTimes WHERE Ärendenr = @TopÄrende
    END
    Arne Olsson

    Hi Arne Olsson, try this..
    DECLARE @Transactions TABLE
    Id1 INT,
    IdStatus INT,
    StatusName VARCHAR(10)
    DECLARE @Stages TABLE
    IdStatus INT,
    StatusName VARCHAR(10)
    INSERT INTO @Transactions VALUES(1,1,'AA'), (1,3,'CC'), (1,5,'EE'), (2,1,'AA'), (2,3,'CC')
    INSERT INTO @Stages VALUES (1,'AA'), (2,'BB'), (3,'CC'), (4,'DD'), (5,'EE')
    ;WITH CTE AS(SELECT DISTINCT Id1 FROM @Transactions)
    SELECT Id1, IdStatus, StatusName FROM CTE, @Stages
    EXCEPT
    SELECT Id1, IdStatus, StatusName FROM @Transactions
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

  • How to populate rows from another table in new blank rows of other table

    I have to convert an oracle form 6i to Jdeveloper application. In forms 6i we use create a cursor for other table and then populate the current table data block row using create record and assigning its values from cursor and then issuing next record until all cursor records are written in data block. After some manual editing we save the whole form and then all block records are saved as new rows in table.
    Now how to create this functionality in jdeveloper application.
    Kindly help.

    two steps-
    1. get row from first VO.iterate them - like below -
    DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
                                    DCIteratorBinding dcIteratorBindings = bindings.findIteratorBinding("ViewObj1Iterator");
                                    HSSFRow  excelrow = null;
                                            // Get all the rows of a iterator
                                            oracle.jbo.Row[] rows = dcIteratorBindings.getAllRowsInRange();
                                        int i = 0;
                                                for (oracle.jbo.Row row : rows) {
                                                                                                                    row.getAttribute(colName).toString());  // by this you can get row attribute value..
    2. inside iteration create row for VO 2 for example-
    ViewObject employee= findViewObject("EmployeeVO");
    // Create a row and fill in the columns.
    Row row = employee.createRow();
    row.setAttribute("Name", "Vinay");
    row.setAttribute("EmpId", 1);
    //Insert row in to the default row set
    employee.insertRow(row);
    Read more: http://www.techartifact.com/blogs/2012/12/creating-new-row-of-view-object-in-adf-techartifact.html#ixzz2iL978UOD
    http://www.techartifact.com/blogs/2012/12/creating-new-row-of-view-object-in-adf-techartifact.html

  • Update one row based on a row from another table

    Hi,
    I have two tables which are having the same field but with a different name.
    CREATE TABLE FAVE_CODE2_NEW_JOIN
    BANKID VARCHAR2(5 BYTE) NOT NULL,
    CUSTOMERID VARCHAR2(12 BYTE) NOT NULL,
    SIXID VARCHAR2(12 BYTE) NOT NULL,
    FAVCODE VARCHAR2(13 BYTE),
    IDX NUMBER(5),
    DEFAULTT NUMBER(1)
    TABLESPACE PORTFOLIO_FAVORITE
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE TABLE SUBSCRIPTION
    SUBSCRIPTIONID RAW(16) NOT NULL,
    APPID VARCHAR2(64 BYTE) NOT NULL,
    DEVICEID VARCHAR2(64 BYTE),
    SUBSCRIBERID NUMBER NOT NULL,
    TIME_REGISTERED TIMESTAMP(6) DEFAULT SYSTIMESTAMP NOT NULL,
    TIME_LAST_USED TIMESTAMP(6) DEFAULT SYSTIMESTAMP NOT NULL,
    SUBSCRIPTION_TYPE VARCHAR2(30 BYTE) NOT NULL,
    SUBSCRIPTION_INFO VARCHAR2(512 BYTE)
    TABLESPACE PORTFOLIO_FAVORITE
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 1M
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    SUBSCRIPTION_INFO in SUBSCRIPTION is equal to SIXID in FAVE_CODE2_NEW_JOIN. They have the same value
    In FAVE_CODE2_NEW_JOIN table there is also a FAVCODE filed.
    Now i want to find out the record from VE_CODE2_NEW_JOIN which are having the same sixid like SUBSCRIPTION_INFO in SUBSCRIPTION and then replace that SUBSCRIPTION_INFO with the value in FAVCODE
    Here are some sample from both tables:
    SUBSCRIPTION:
    B31E5F5D3CB6     RIe9pnbe7BtA8IuQ     BB2-58CA815F9958     21     2012-01-10 19:18:39     2012-01-11 12:24:04     FT     FSB0650444
    010FB3AE74AE     RIe9pnbe7BtA8IuQ     845-AD375E95ED90     21     2012-01-12 08:31:47     2012-01-24 08:53:09     FT     FSB0650444
    6119E731A26F     RIe9pnbe7BtA8IuQ     76A-DAD2E359BF3F     113     2012-01-04 00:25:05     2012-01-19 16:17:21     FT     FSB0632948
    FAVE_CODE2_NEW_JOIN:
    08999     191111111111     FSB0650444     SWB0553263     11     0
    As you see they both have the same 'FSB0650368' but i want to replace this code with the corresponding FAVCODE in FAVE_CODE2_NEW_JOIN which is 'SWB0553263'.
    I hope you have got what i mean, please tell me to explain more if you have any problem to understand what i mean.
    Many thanks in Advance!
    / Hesam

    Hesam wrote:
    hi,
    I'm trying this code:
    update subscription a
    set a.subscription_info =
    select b.favcode
             from fave_code2_new_join b
            where b.sixid = a.subscription_info
    where exists
    select b.favcode
             from fave_code2_new_join b
            where b.sixid = a.subscription_info
    )but its taking a lot of time. Until now 10 minutes and lots of presure on the CPU!!
    Can we optimize this or its just due to the number of records?
    Edited by: Hesam on Mar 25, 2013 3:01 PMSo now you are getting into performance issues?
    I would suggest you read {message:id=9360003} and post the necessory details so that we can see what can be improved and how.

  • INSERTING INTO A TABLE FROM ANOTHER TABLE

    Hi,
    I am having a table called emp in which 5 columns are there, I want to insert some rows from another table called employees, only into three columns of emp table through a sub query.
    Is this scenario is possible, I tried so many queries but it is not working out.
    Can any body help me out.
    The columns in emp table is
    empno, ename, doj, designation, salary, deptno, mgrid
    The columns in employees table is
    empno, name, hiredate, post, salary, commission, deptno, mgr
    I want to insert into empno, ename, doj, designation columns of emp table from the employees table empno, name, hiredate, post columns.
    Ramesh.

    It looks like your EMP table has 7 columns, not 5, and you want to insert into 4 columns, not 3.
    insert into emp
      (empno, ename, doj, designation)
      select empno, name, hiredate, post
        from employees;

  • Copying table rows from one table to another table form

    Hi
    I have a problem about Copying table rows from one table to another table form.On jsf pages if you enter command button go anather jsf page and it copy one row to another table row. But when i execute this process for table FORM it doesn't copy I wrote a code under "createRowFromResultSet - overridden for custom java data source support." Code block is:
    ViewRowImpl value = super.createRowFromResultSet(qc, resultSet);
    try{
    AdfFacesContext fct = AdfFacesContext.getCurrentInstance();
    Number abc = (Number)fct.getProcessScope().get("___");
    value.setAttribute("___",abc);
    }catch(Exception ex){System.out.println(ex);  }
    return value;

    Table may be copied with the
    expdp and impdp utilities.
    http://www.oracle.com/technology/products/database/utilities/index.html

  • How to populate a table based on a row selection from another table.

    Hi, i just started to use ADF BC and Faces. Could some one help me or point me a solution on the following scenario .
    By using a search component , a table is being displayed as a search result. If i select any row in the resulted table , i need to populate an another table at the bottom of the same page from another view. These two tables are related by primary key . May i know how to populate a table based on a row selection from another table. Thanks
    ganesh

    I understand your requirement and the tutorial doesn't talk about Association between the views so that you can create a Master-Detail or in DB parlance, a Parent-Child relationship.
    I will assume that we are dealing with two entities here: Department and Employees where a particular Department has many Employees and hence a Parent-Child relationship.
    Firstly, you need to create an Association between the two Entities - Department and Employees. You can do that by right clicking on the model's entity and then associating the two entities with the appropriate key say, DepartmentId.
    Once you have done that, you need to link the two entities in the View section with this Association that you created. Then go to AppModule and make sure that in the Available View Objects: 'EmployeesView' appears under 'DepartmentView' as "EmployeesView via <link you created>". Shuttle the 'DepartmentView' to the right, Data Model and then shuttle
    "EmployeesView via <link you created>" to the right, Data Model under 'DepartmentView'.
    This will then be reflected in your Data Controls. After that, you simply would have to drag this View into your page as a Master-Detail form...and then when you run this page, any row selected in the Master table, would display the data in the Detail table.
    Also, refer to this link: [Master-Detail|http://baigsorcl.blogspot.com/2010/03/creating-master-detail-form-in-adf.html]
    Hope this helps.

  • Deleting rows from one table while filter condition lies into another table

    Hi All,
    I'm facing a problem deleting a row from a table where the condition lies in other table. To ealaborate the scenario further let's say I have two table T1 (transaction table) and T2 (Master Table). I want to delete a record from table T1 by checking some conditions lies in table T2.
    I tried with the below query but this query deleting records from both the table.
    DELETE FROM ( SELECT * FROM T1 top INNER JOIN T2 tp
    ON top.TID = tp.TID
    WHERE top.DEAL_SITE_ID = inputparameter1
    AND (TP.SEGMENT <>inputparameter2 OR tp.segment is not null));
    Here the record is getting deleted from both the tables but I don't want to delete data from my master table i.e table T2.
    Any help would be highly appreciated. Thanks in advance.
    Regards,
    Subhadeep

    SQL> select *
      2   from the_table;
    X          Y
    AA         a
    BB         a
    CC         a
    AA         b
    DD         b
    SQL> select *
      2   from the_table_2;
    X          Y
    AA         a
    BB         a
    CC         a
    SQL>  delete from
      2  (
      3  select *
      4  from the_table  t1 inner join the_table_2 t2
      5  on  t1.x = t2.x
      6  and t1.y = t2.y);
    3 rows deleted.
    SQL> select *
      2   from the_table;
    X          Y
    AA         b
    DD         b
    SQL> select *
      2   from the_table_2;
    X          Y
    AA         a
    BB         a
    CC         a

  • Want to add rows from database in custom table model

    Hello all,
    I have written custom table model which has single blank row intially.
    Once user clicks on button, i want to add more rows in custom table model and display them in JTable.
    I have created JTable object as shown below.
    Jtable patientTable = new JTable( new DiagnosticTableModel());
    My custom tabel model is as shown below.
    import javax.swing.table.AbstractTableModel;
    public class DiagnosticTableModel extends AbstractTableModel
         private String[] columnNames = {
                         "Date",
                                              "Diagnosis",
                                              "Severity",
                                              "Medications"};
         private String[][] data = {
          public int getColumnCount()
             return columnNames.length;
          public int getRowCount()
               return data.length;
          public String getColumnName(int col)
             return columnNames[col];
          public Class getColumnClass(int col)
             return getValueAt(0, col).getClass();
          public Object getValueAt(int row, int col)
             return data[row][col];
          public boolean isCellEditable(int row, int col)
          return true;
          public void setValueAt(Object value, int row, int col)
             data[row][col] = value.toString();
             fireTableCellUpdated(row, col);
    }Thanx a lot in advance.

    I have written custom table model which has single blank row intially.Why did you write a custom TableModel? The DefaultTableModel will work fine and it has methods that allow you to dynamically add rows to the table.

  • Autocomplete from another table in another sheet in same file

    I found how to get a price to autofill using VLOOKUP. I like it.
    Now, I want to be lazier and not need to type in the full item name in the row heading completely & exactly every time. I also don't want to have a drop down menu in every item line in each table unless there is no better alternative. I would like Numbers to autofill from an inventory list (table with quantities, prices, etc.) in another sheet. It seems that I should have been able to find this function explained but my searches were inadequate.
    Then, I will want Numbers to automatically update another column in the inventory table with the quantity of that item sold & the amount remaining which will cause calculations for the value remaining & sold in other columns (without changing the original inventory column). It seems to me that the formula may require numbers to search each table in each sheet for the item name in that row and add all sale quantities together. This means that the formulas would be constantly searching which sounds like it could slow things down a bit. So, again, maybe there's a more efficient way of doing this.
    Please help me find these efficiency tools. ThankU

    Mr. "P" wrote:
    I want to copy an entire row from one table in one sheet to another table in another sheet retaining all values and formulas? So that if I make a change in the original sheet it propagates to the other sheet
    (1) A change in the original will propagate to the other table if the change is in the 'copied' row.
    (2) what you require can't be achieve by a copy process.
    It requires the use of external references which are perfectly described in the User Guide (page 122 in the English version).
    (3) sure, a reference is a cell's attribute so you will have to enter it in every cell of the row.
    When it's done for one row you may use the Fill Down tool which is also described (with quite all you need to use Numbers) in the User Guide.
    Yvan KOENIG (from FRANCE vendredi 19 juin 2009 15:53:03)

  • Fetching more than one row from a table after selecting one value from the dropdown

    Hi Experts,
    How can we fetch more than one row from a table after selecting one value from the dropdown.
    The scenario is that I have some entries in the dropdown like below
      A               B               C        
    11256          VID          911256  
    11256          VID          811256
    11256          SONY      11256
    The 'B' values are there in the dropdown. I have removed the duplicate entries from the dropdown so now the dropdownlist has only two values.for eg- 'VID' and'SONY'. So now, after selecting 'VID' from the dropdown I should get all the 'C' values. After this the "C' values are to be passed to other methods to fetch some data from other tables.
    Request your help on this.
    Thanks,
    Preeetam Narkhede.

    Hi Preetam!
    I hope I understand your request proberly, since this is more about Java and less about WebDynpro, but if I'm wrong, just follow up on this.
    Supposed you have some collection of your original table data stored in variable "origin". Populate a Hashtable using the values from column "B" (let's assume it's Strings) as keys and an ArrayList of whatever "C" is (let's assume String instances, too) as value (there's a lot of ways to iterate over whatever your datasource is, and since we do not know what your datasource is, maybe you'll have to follow another approach to get b and c vaues,but the principle should remain the same):
    // Declare a private variable for your Data at the appropriate place in your code
    private Hashtable temp = new Hashtable<String, ArrayList<String>>();
    // Then, in the method you use to retrieve backend data and populate the dropdown,
    // populate the Hashtable, too
    Iterator<TableData> a = origin.iterator();
    while (a.hasNext()) {
         TableData current = a.next();
         String b = current.getB();
         String c = current.getC();
         ArrayList<String> values = this.temp.get(b);
         if (values == null) {
              values = new ArrayList<String>();
         values.add(c);
         this.temp.put(b, values);
    So after this, you'll have a Hashtable with the B values als keys and collections of C values of this particular B as value:
    VID --> (911256, 811256)
    SONY --> (11256)
    Use
    temp.keySet()
    to populate your dropdown.
    After the user selects an entry from the dropdown (let's say stored in variable selectedB), you will be able to retrieve the collection of c's from your Hashtable
    // In the metod you handle the selection event with, get the c value collection
    //and use it to select from your other table
    ArrayList<String> selectedCs = this.temp.get(selectedB);
    // now iterate over the selectedCs items and use each of these
    //to continue retrieving whatever data you need...
    for (String oneC : selectedCs) {
         // Select Data from backend using oneC in the where-Clause or whatever...
    Hope that helps
    Michael

  • Get exact row from database table

    This is part of my source code that displays one row from getQuest recordset. Always first.
    <body>
    <p><?php echo $row_getQuest['content']; ?></p>
    <p>: <?php echo $row_getQuest['prom1']; ?></p>
    <p><?php echo $row_getQuest['prom2']; ?></p>
    <?php echo $row_getQuest['dos1']; ?>(); <?php echo $row_getQuest['dos2']; ?> (); <?php echo $row_getQuest['dos3']; ?> (); <?php echo $row_getQuest['dos4']; ?>(); <?php echo $row_getQuest['dos5']; ?> (); <?php echo $row_getQuest['dos6']; ?> (); <?php echo $row_getQuest['dos7']; ?> ().
    </body>
    Can i change it so, that on this page it always displayed row with exact position in the table - for example second or 15th - independently of row contents and rows deletition, moving or changing in table?

    But if I add 5 rows to table, then delete all of them and add 5 again - auto incremented id will 6 for first in table and 10 for last. If i delete all and add 5 again it will be 11...15 and so on. As I said - I cannot rely on row contens - because I'm planning to delete and add data from that table frequently. Or other solution could be to allways keep id from 1 to [amount of rows]. I do not know how this is done.
    Or am I wrong about id?

  • FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.

    Hi,
    I have one multi record block in which i want to fetch values
    (more then one record) from another table using select statement
    IN KEY NEXT ITEM.I am getting following error.
    ORA-01422: exact fetch returns more than requested number of rows
    Thanks in advance.

    In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
    Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
    However, you can replace the explicit cursor with implicit one like
    go_block('non_db_block_name');
    first_record();
    FOR v_tab IN (SELECT *
    FROM tab
    WHERE col_name = :variable)
    LOOP
    :non_db_block_name.field1 := v_tab.col1;
    :non_db_block_name.field2 := v_tab.col2;
    next_record();
    END LOOP;

  • How NOT to restrict no of rows from two tables

    I have two identical tables Invoice and Payment. The only difference is Invoice_id,Invoice_Amt and Payment_id,Payment_Amt columns that shows different ids and amounts. The bank_ids, names, account_types are same. Invoice table has 3 rows and Payment has 2. Simply meaning that there were 3 invoices generated but the bank received 2 payments. I want to show Invoice_Amt and Payment_Amt using sql query. But its giving me total 6 rows. Whereas, I want 3 from Invoice and 2 rows from Payment table to show side-by-side.
    CREATE TABLE invoice
    ( invoice_id NUMBER
    bank_id NUMBER,
    bank_name VARCHAR2(256),
    invoice_amount NUMBER);
    ----Invoice table has 3 rows showing 3 Invoice Amts
    CREATE TABLE payment
    ( payment_id NUMBER
    bank_id NUMBER,
    bank_name VARCHAR2(256),
    payment_amount NUMBER);
    ----Payment table has 2 rows showing 2 Payments
    After executing this sql statement below, I get 6 rows:
    select inv.invoice_amount,pymt.payment_amount from invoice inv,payment pymt where inv.bank_id=pymt.bank_id;
    How can I show 3 rows for Invoice and 2 for Payment..?
    Thank you.

    Hi,
    So you want
    the 1st invoice to appear side-by-side with the 1st payment,
    the 2nd invoice to appear side-by-side with the 2nd payment,
    the nth invoice to appear side-by-side with the nth payment.
    But, if there are an uneqaul numner of payments and invoices, all the payments and all the invoices must still be shown, alone on a row if necessary.
    That sounds like a job for FULL OUTER JOIN.
    Use the analytic ROW_NUMBER fucntion to determine which is the 1st, 2nd, ..., nth row in each table, for each bank.
    WITH     invoice_plus_r_num     AS
         SELECT     bank_id, bank_name
         ,      invoice_amount
         ,     ROW_NUMBER () OVER ( PARTITION BY  bank_id, bank_name
                                   ORDER BY          invoice_id
                           )         AS r_num
         FROM    invoice
    ,     payment_plus_r_num     AS
         SELECT     bank_id, bank_name
         ,      payment_amount
         ,     ROW_NUMBER () OVER ( PARTITION BY  bank_id, bank_name
                                   ORDER BY          payment_id
                           )         AS r_num
         FROM    payment
    SELECT       NVL (i.bank_id,   p.bank_id)          AS bank_id
    ,       NVL (i.bank_name, p.bank_name)     AS bank_name
    ,       i.invoice_amount
    ,       p.payment_amount
    FROM          invoice_plus_r_num     i
    FULL OUTER JOIN     payment_plus_r_num     p  ON   i.bank_id     = p.bank_id
                                        AND     i.bank_name     = p.bank_name
                                AND     i.r_num          = p.r_num
    ORDER BY  bank_id     -- you can use column aliases here
    ,       bank_name
    ,       NVL (i.r_num, p.r_num)
    ;You mentioned something about accounts, but didn't include that in the CREATE TABLE statements. You'll probably want to add that wherever I used bank_id and bank_name, above.
    Are invoce and payment actually views, rather than tables? If not, you should have a separate bank table, and only include the bank_id in the other tables.
    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.
    Edited by: Frank Kulash on Feb 3, 2011 12:32 PM

  • SQL select a concatination of entries from another table

    I am trying to select a few columns from one table and then add another column that is a concatination or names from another table that referances it as below. Is this possible to do in one select statement?
    table x1
    ID NAME
    1 Bob
    1 Tom
    2 Bill
    table x2
    ID NAMES
    1 Bob, Tom
    2 Bill
    3

    You mean string aggregation?
    If yes, then it is possible like this, if you are on 10g.
    SQL> create table x1 (id,name)
      2  as
      3  select 1, 'Bob' from dual union all
      4  select 1, 'Tom' from dual union all
      5  select 2, 'Bill' from dual
      6  /
    Tabel is aangemaakt.
    SQL> select id
      2       , rtrim(n,', ') names
      3    from ( select id
      4                , n
      5                , rn
      6             from x1
      7            model
      8                  partition by (id)
      9                  dimension by (row_number() over (partition by id order by null) rn)
    10                  measures (cast(name as varchar2(20)) n)
    11                  rules
    12                  ( n[any] order by rn desc = n[cv()] || ', ' || n[cv()+1]
    13                  )
    14         )
    15   where rn = 1
    16  /
            ID NAMES
             1 Bob, Tom
             2 Bill
    2 rijen zijn geselecteerd.There are several other (slower) techniques possible as well. You can find them by using the search function on this forum.
    Regards,
    Rob.

Maybe you are looking for