Contatenation of columns from two different tables

Hi everyone
i have one table in following desc
table-1
str q4_currrent Q4_target
prd 500 1000
Table-2
q3_currrent Q4_target
345 1000
Table-3
percentage
50
I want the result in this format---
str q4_currrent Q4_target q3_currrent Q4_target percentage
prd 500 1000 345 1000 50
Can anyone help me how can i get this result? I want this to be done only with
query not with any procedure or function.
if you hav any query to concatenate the different tables please suggest.
thanks.
-Anand

hi
thw solution which you have given that is giving the
cartesian product of all the rows of the all the 3
tables.
1st table-7 rows
2nd table-7 rows
3rd table-7 rows
total rows in result table- 343 rows.
So its not working well..
thanks for ur response.What part of
You might also want a WHERE clause if the tables have more than one row in.did you have a problem with? You provided no information on which any of us could have written a join condition. I assumed you either had only the one row you showed us, or you were planning on coding the join yourself.

Similar Messages

  • Sum two different columns from two different tables

    Can you select and sum two different columns, from two different tables in the same sql statement?
    i.e.
    table1
    Item----OnHand_Qty
    A--------10
    A--------15
    B--------10
    B--------10
    C--------20
    table2
    Item----Trx_Qty
    A--------2
    A--------4
    A--------6
    B--------1
    B--------1
    C--------4
    I'm looking for the following results from a query
    Item----Sum(Onhand_Qty)---Sum(Trx_Qty)
    A--------25

    Like this?
    SQL> create table table1 (item,onhand_qty)
      2  as
      3  select 'A', 10 from dual union all
      4  select 'A', 15 from dual union all
      5  select 'B', 10 from dual union all
      6  select 'B', 10 from dual union all
      7  select 'C', 20 from dual union all
      8  select 'D', 30 from dual
      9  /
    Tabel is aangemaakt.
    SQL> create table table2 (item, trx_qty)
      2  as
      3  select 'A', 2 from dual union all
      4  select 'A', 4 from dual union all
      5  select 'A', 6 from dual union all
      6  select 'B', 1 from dual union all
      7  select 'B', 1 from dual union all
      8  select 'C', 4 from dual union all
      9  select 'E', 3 from dual
    10  /
    Tabel is aangemaakt.
    SQL> select nvl(t1.item,t2.item) item
      2       , t1.sum_onhand_qty
      3       , t2.sum_trx_qty
      4    from ( select item, sum(onhand_qty) sum_onhand_qty
      5             from table1
      6            group by item
      7         ) t1
      8         full outer join
      9         ( select item, sum(trx_qty) sum_trx_qty
    10             from table2
    11            group by item
    12         ) t2
    13         on (t1.item = t2.item)
    14  /
    I SUM_ONHAND_QTY SUM_TRX_QTY
    A             25          12
    B             20           2
    C             20           4
    E                          3
    D             30
    5 rijen zijn geselecteerd.Regards,
    Rob.

  • How to create a foreign key for the table from two different tables?

    Hi All,
    I have a three table like below. In the below table SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK will be having the primary key for NAME column. The same SAMPLE_CONS3_CHECK table also having the primary key for NAME column and forieign key for SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK tables. See the below code 2
    code 1:
    CREATE TABLE SAMPLE_CONS_CHECK
            (NAME VARCHAR2(10),
            SERIES  VARCHAR2(5)
    CREATE TABLE SAMPLE_CONS2_CHECK
            (NAME  VARCHAR2(5),
             MODEL  NUMBER
    CREATE TABLE SAMPLE_CONS3_CHECK
            (NAME  VARCHAR2(5),
             MODEL_NO  NUMBER
            )code 2
    alter table SAMPLE_CONS_CHECK
    add constraint SAMPLE_CONS_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS2_CHECK
    add constraint SAMPLE_CONS2_CHECK_pk primary key (NAME)
    alter table SAMPLE_CONS3_CHECK
    add constraint SAMPLE_CONS3_CHECK_pk primary key (NAME)
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK1 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS_CHECK
        NAME
    ) ON DELETE CASCADE;
    ALTER TABLE SAMPLE_CONS3_CHECK ADD
    CONSTRAINT SAMPLE_CONS3_CHECK_FK2 FOREIGN KEY
         NAME
    ) REFERENCES SAMPLE_CONS2_CHECK
        NAME
    ) ON DELETE CASCADE;From the above schenario i am able to insert the data to SAMPLE_CONS3_CHECK table. But the parent data is already available in the parent table. The problem is here two different constarints from two different tables. While inserting, it is checking from both the tables whether the parent is exist or not.
    How can i solve this problem? Can anyone halp me about this?
    Thanks
    Edited by: orasuriya on Aug 8, 2009 2:02 AM

    Actually the design is completely incorrect.
    What you say is
    I have
    'foo', 'foo series'
    'foo','foo model'
    'foo',666
    By virtue of table3 referring to both table1 and table2.
    This means you actually need to have 1 (one) table:
    'foo','foo series','foo model', 666
    And the 'problem' disappears.
    Sybrand Bakker
    Senior Oracle DBA

  • Concatenate columns from two different reports

    In OBIEE 11g report, I am looking for a method to concatenate columns from two different reports.
    My requirement is, if I show 'Units Produced' for customer A, I need to show another column 'Units Produced' for a related customer B.
    Every customer has one related customer.
    So my report shows all the data for customer A, but I need to add one column which is for custome B , so I am looking a way to concatenate columns or if some other way this can be done

    Customer A is dimension table. You mapped to fact to get Customer A details.
    Now you want for Customer B. Now create one more alias table for Customer and name it as customer B and join with Fact on Customer B keys and use it.
    Each customer has related customer.
    2 dimension tables one for customer and other for related customer.

  • Selecting data from two different tables.

    Do we need to use join two tables with primary/foreign key while trying to use select statement for getting data from those to table.? If no who can i go about do it.

    872959 wrote:
    If i am using From clause to get data from two different tables, is it necessary that both tables have column of identical data in them.In general, they ought to (or you need to join in a third table that tells you how to map rows from one table to rows of the other table).
    It is not strictly necessary that there be any join condition between tables. If you don't provide a join condition, Oracle has to do a Cartesian product. That means that if there are n rows in one table and m rows in the other, the result set will have n * m rows. It is very rarely a good idea to write queries that do Cartesian products but it does occasionally happen.
    Justin

  • To find Common data in 2 columns in two different tables.

    Hi,
    Could someone help me out with a querry to find out common data from 2 columns in two different tables??
    Thanks
    Rajesh

    966915 wrote:
    suppose i hav 2 tables
    Table A
    s.No name EID
    1 aaa 123
    2 bbb 234 ... etc..
    and Table B
    S.no salary eid location
    1 mmm$ 123 india
    2 ddd$ 556 Uk
    3 fff$ 236 US
    How do i select the common entry in both the tables??why do you post in forum for SQL & PL/SQL; yet never post anything in either language?
    what do you mean by "common enrty"?
    does every column value must match exactly across 2 rows in different table?

  • How to Create a new column from two different result sets

    How to Create a new column from two different result sets, both the result set uses the different date dimensions.

    i got solutions for this is apply filters in column formula it self, based on the requirement.

  • Discoverer columns from two different sheets

    Hi,
    Is it possible in discoverer to bring columns from a different sheet into another sheet? I have a few columns on sheet2, which have a different condition and sheet1 has different conditions. The sheets 1 and 2 can be linked on their emplid. Is there a way to combine the columns??
    Any help is greatly appreciated.
    Thanks!

    Hi,
    I am using decode to try and get the column with the condition into the first sheet.
    For example:
    In my first sheet, I select emplid, empl_no, area_cde, avg_eqty from table a.
    I also want the following from table a:
    1) count rec_id where a_cde in (1,2,3)
    2) count rec_id where a_cde in (1,2,3) and product_cde = 1 and discnt = 1
    When I use decode, and select the columns, I say,
    calc1:
    decode(a_cde,1,1,2,1,3,1) --> seperating a codes 1,2,3 and the rest of them.
    calc2:
    and then I calculate another item --> case when calc1 = 1 then count(rec_id) else NULL end
    When I do the above, I get one row as expected.
    However, when I try to incorporate 2), I created another calculation:
    calc3:
    case when calc1 = 1 and product_cde = 1 and discnt = 1 then count(rec_id)
    As soon as I add this calc to my report, I get 2 rows returned, because, the Avg_discnt column (just the col selected from the table, not a calc), has a discnt = 1 associated with it, and I get two rows instead of one row.
    Please let me know if posting the SQL generated by discoverer would be more clearer.
    Thanks for your inputs!
    Edited by: spriya on Apr 6, 2010 2:16 PM

  • Extracting unique records from two different tables record

    Hello,
    In the following code of two different tables www.testing.com exists in both tables. I want to compare two different columns of the two different tables to get unique records.
    SQL> select unique(videoLinks) from saVideos where sa_id=21;
    VIDEOLINKS
    www.testing.com
    SQL> ed
    Wrote file afiedt.buf
      1* select unique(picLinks) from saImages where sa_id=21
    SQL> /
    PICLINKS
    test
    test14
    www.hello.com
    www.testing.comThanks & best regards

    Unfortunatly you didn't mention the expected output. I guess it would be the one line
    "www.testing.com"
    in that case simply join the two tables.
    select *
    from saVideos v
    join saImages i on i.sa_id = v.sa_id and i.picLinks = v.videoLinks
    where v.sa_id=21;If needed then you could change the select list to retrieve only distinct values.
    select unique v.sa_id, v.videolinks
    from saVideos v
    join saImages i on i.sa_id = v.sa_id and i.picLinks = v.videoLinks
    where v.sa_id=21;I usually avoid distinct/unique whereever possible. This requires the database to do a sort and makes the query slow.
    Edited by: Sven W. on Feb 10, 2011 1:55 PM

  • Query from two different tables

    Hi All
    I am having two different tables A and B. I want to select all rows containing the names like the rows in B.
    I have tried the below and it does not work:
    select * from A where name like (select '%'||name||'%' from B).
    Can anyone help please.
    Thanks
    Amit

    Hi Jeneesh
    Thanks for the quick reply.
    What i want is query to bring back all the name containing the string which is to be found in the table B.
    Table A's content
    Amit
    Amita
    Anjoo
    Table B's Content
    Ami
    Query should return
    Amit
    Amita

  • Can't get table field from two different tables if named same

    select c.notes, o.notes
    from cusomters c, orders o
    :does not work in getting the RS.
    :if i change database to:
    select c.customer_notes, o.order_notes
    from cusomters c, orders o
    :then it works.
    :i make PURE DYNAMIC META SQL database
    applicaitons, and i need for abstract SQL tables.
    i have the same problem in getting
    the max values:
    select
    max(height),
    max(weight),
    max(age)
    from person_stats
    group by geographical_area

    When you select from 2 different tables you need to join them on some condition, otherwise it has no idea how to associate the 2 tables together.
    try select c.notes, o.notes from cusomters c, orders o where c.customer_id = o.customer.id or whatever the join fields are.
    For the group by I believe you have to include the field that you group by:
    select geopraphical_area, max(height), max(weight), max(age) from person_stats group by geographical_area
    give them a try
    Jamie

  • Inserting data into a column from 2 different tables

    Hi,
    I need to insert data into a table using 2 other tables. The tables that contain data have identical column names.
    Is using a UNION statement the only option?
    Also, if I need to insert data into columns from only one of the either tables, how do i do it?
    Thanks.

    For future reference, "doesn't seem to work" is a rather generic description... Posting the particular error message will be quite helpful, though I'm reasonably confident that I know the particular problem here.
    First, if only for sanity, you probably want to explicitly list the columns of the destination table in your INSERT statement.
    Second, it doesn't make sense to have DISTINCT clauses in queries that are UNION-ed together. A UNION has to do a sort to remove duplicates already.
    Third, the two queries you are UNIONing together have to return the same number of columns, with the same names, in the same order.
    You probably want something like
    INSERT INTO new_table( col1, col2, col3, col4, col5 )
      SELECT 'ABC'  col1,
             a.colA col2,
             a.colB col3,
             a.colC col4
             a.colD col5
        FROM table1 a
      UNION
      SELECT 'ABC'  col1,
             b.colA col2,
             b.colB col3,
             b.colC col4
             NULL   col5
        FROM table2 bJustin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How do I fill a column from a different table

    I am using numbers V3.5 on Yosemite V10.10 and have a question about filling table columns.  I want the new table to ignore some values in the original column.  The first table is a has a matrix of values for multiple stocks and accounts.
    I would like to create a new table for a specific account with only the stocks listed that have a value > $0.  The table would appear something like this.
    I have looked at other posts but could not apply what I have found to this problem.  TIA for any suggestions

    Hi Marty,
    I would suggest you use a filter on your account column- >0 after your bring your data over.
    quinn

  • Compare 2 Columns using SSIS from two different tables

    Hello,
    A newbie to ssis.
    I have a Table 1 with Address Details and Table 2 with Address Details of same customer but from different sources. I have loaded these two data sources and also joined these two tables.
    I want to compare address column of one table with the other table, if they are not equal need to insert into another table.
    With Sql query we can perform it, but just want to know how to perform this with ssis.

    You can use the
    LookUp Transformation
    Arthur
    MyBlog
    Twitter

  • Adding two column data  from two different tables.

    Hi, I have two tables i want to add two column with same id and put it in third table
    T1 is
    id Value
    1 50
    2 100
    3 500
    4 75
    T2 is
    id Value
    3 -20
    4 80
    5 -30
    6 -10
    I want the out put as
    1 50
    2 100
    3 480
    4 155
    5 -30
    6 -10
    i have written
    select a.id,a.value+b.value from t1 a,t2 b where a.id=b.id(+)
    this is not giving me the id's from t2.

    select id, sum(value) from
    (Select id,value from t1
    union
    select id ,value from t2
    )group by id;

Maybe you are looking for

  • Adobe Flash and Flash based Video Players and the ps command

    OK, I have two v20z servers. I just reinstalled Solaris 08/07 on both of them. These are both Sunray servers. One of the servers is fully patched and has SRSS 4.0 installed and serving Sunrays just nicely. I just finished installing Solaris on the 2n

  • Why can I not download my Shop purchased artwork from itunes

    I have been tring to get the artwork for my Purchased CD's but when I try to get it from itunes it does not load anything any body got an answer for this has i have loads of cd Music without artwork?????? Help Please

  • ICloud duplicating contacts.

    How can I create a "clean" list and go from there. If I delete on one it doesn't delete on others. I'm using an IPad, IPhone & a PC (Outlook 2007). Would like to clean up on PC (easier typing). How to go about this?

  • Why use J2EE?

    I have to start convincing a few people at work why we should make a move to J2EE. Why should we use J2EE, in particular EJBs on a payment processing type system. Personaly I have used EJBs, but the extent of "Hello World" type applications...

  • Multiple libraries - View them simultaneously?

    I'm upgrading from iPhoto 2 on my old powerbook. I have about 4 libraries (not by choice) that have many duplicate photos between them. I would like to delete the duplicates and end up with one nice neat library of about 4000 photos. My preference wo