How to join two tables such as union all

We have two tables ,there has the same structure,one is the recent Table,the other is a history Table。How can i get the reasult from the two tables .
I know we can create the table using table type=select and write the SQL.
I want to know another way such as fragmentaion content,But i don`t know how to implement.
Who can give the step by step .
Thank you very much.

I set the wrong case .my question has been answered..
Thank you ~
Edited by: Richard 1982 on 2009-12-27 下午9:55

Similar Messages

  • How to join two tables

    hi
    how to join two tables using inner join  if the first table has two primary keys and second table has 3 primary keys

    Would describe type of joins in ABAP, which might differ with other joins.
    The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of INNER JOIN or LEFT OUTER JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
    On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
    AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
    The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
    At least one comparison must be specified after ON.
    Individual comparisons may be joined using AND only.
    All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
    The following additions not be used: NOT, LIKE, IN.
    No sub-queries may be used.
    For outer joins, only equality comparisons (=, EQ) are possible.
    If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
    In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
    Resulting set for inner join
    The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
    Resulting set for outer join
    The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
    Note
    If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~.
    Example
    Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
    p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
    fldate TYPE sflight-fldate,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
    WITH UNIQUE KEY fldate carrname connid.
    SELECT ccarrname pconnid f~fldate
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( scarr AS c
    INNER JOIN spfli AS p ON pcarrid = ccarrid
    AND p~cityfrom = p_cityfr
    AND p~cityto = p_cityto )
    INNER JOIN sflight AS f ON fcarrid = pcarrid
    AND fconnid = pconnid ).
    LOOP AT itab INTO wa.
    WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Example
    Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
    PARAMETERS p_cityfr TYPE spfli-cityfrom.
    DATA: BEGIN OF wa,
    carrid TYPE scarr-carrid,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa,
    itab LIKE SORTED TABLE OF wa
    WITH NON-UNIQUE KEY carrid.
    SELECT scarrid scarrname p~connid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM scarr AS s
    LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
    AND p~cityfrom = p_cityfr.
    LOOP AT itab INTO wa.
    IF wa-connid = '0000'.
    WRITE: / wa-carrid, wa-carrname.
    ENDIF.
    ENDLOOP.

  • How to join two tables with no similar columns

    Hi all,
    I have two tables as follows:
    Table T1 have Attributes as follows:
    GLCODE,
    BRANCH,
    ITEM_NUMBER,
    DEMAND_DATE,
    QUANTITY,
    SOURCE
    Table T2 have Attributes as follows:
    FORECAST_DATE
    Now in SQL if run the following stattement iam getting out put.
    SELECT GLCODE,BRANCH,ITEM_NUMBER,DEMAND_DATE,QUANTITY, SOURCE,(SELECT DISTINCT FORECAST_DATE FROM T2) FROM T1
    The above SQL Statement giving correct results for me.
    The same SQL Statement how can we implement in mapping level?
    Regards,
    Ava

    Jaap van,
    >
    You have to specify an outer join, but how do you do that if there is no join to begin with? I would do the following (which I didn't test yet):
    add an extra column (say C_JOIN) to the T2-ingroup of the join operator and fill it with from a constant operator with say value 1. Then use T2.C_JOIN (+) = 1 as the join condition.
    If every record in T2 is guaranteed to have the same value, instead of using a deduplicator, which will read all records, sort them and deduplicate them, you can use a filter with filter condition ROWNUM < 2, which only will read one record.
    I am facing almost the same problem but not entirely thou and I was wondering if you have an idea how to even start.
    Problem:
    I got this table:SQL> desc ita.tpis32_job_status
    Name Null? Type
    JOBID NOT NULL NUMBER
    T1_ID NUMBER
    QID NUMBER
    REQ_TYPE VARCHAR2(10)
    SUBMIT_TIME DATE
    OWNERID VARCHAR2(30)
    DESCRIPTION VARCHAR2(150)
    STARTTIME DATE
    ENDTIME DATE
    STATUS VARCHAR2(50)
    ERROR_ID NUMBER
    TABLE_NAME VARCHAR2(30)
    SERVER_ID VARCHAR2(10)
    DATABASE VARCHAR2(20)
    PRIORITY NUMBER
    NUM_LINES NUMBER
    PROCESS_ID NUMBER
    QUE_TIME NUMBER
    STATUS_CODE NUMBER
    ERROR_MSG VARCHAR2(500)
    NUM_LINES_TS NUMBER
    REMOTE_STATUS NUMBER
    This the above table, i am looking for JOBID (a five digit number) like 25875.
    What I want to do is add or append this five digit number to a string to find the corresponding table in dba_tables or all_tables. The only way I have try to do this is by writing PLSQL as you see from here:
    Re: Use PLSQL to delete tables dynamically
    When the select is writing properly, the result of the five digit number from JOBID and the string should look like the below result (job_(five digit_%).
    My problem is there is no relationship between ALL_TABLES and the my own table (ita.tpis32_job_status). Any help will be appreciated.
    TABLE_NAME
    JOB_58871_OUTDATA
    JOB_58868_TS
    JOB_58868_OUTDATA
    JOB_58867_TS
    JOB_58867_CMDLBL_2
    JOB_58867_OUTDATA
    JOB_58866_TS

  • How to  Join two tables using the Inner Join

    Hi All,
    I have two tables i.e table1 and table2 as i have created two otds and my present requirement is to join this two tables and get the results and using this i need to do some logic and update another table3.
    can some one help me out how to go for the above req.
    Thanks in Advance
    Srikanth

    The best efficient way to use inner join is create two input otds,use there otd's in create a collaboration usinf etl.
    after selecting two input otd's create a inner join statement and map it to out put otd.
    while using the etl the performance of the over all integration is increased 20 time of the normal integration.
    Hopes this will helps,,
    Thanks,
    Papa Rao.

  • How to join two tables and get the supply delivery date next to order?

    So there are two tables. One has customer's order no, ordered date, order quantity, available quantity and code of article-
    The other table comes form supply side where we have supply order no, article number, ordered qty, and delivery date.
    We keep stock so this can not be MOT (made to order) system.
    What i need is correct date of arrival to appear next to cusotmers spoecirfic order. The older cusotmers order get's the parts first, second oldest order is next in line etc.
    here is any example
    customer's order
    ref order
    art. code
    ordered qty
    available qty
    order date
    1809202491
    700497
    60
    0
    3.7.2014
    1809200528
    700497
    13
    0
    20.6.2014
    1809198640
    700497
    7
    0
    9.6.2014
    supply order
    supply order
    art. code
    qty orderd
    date of arrival
    4501243378
    700497
    50
    4.8.2014
    4501263437
    700497
    20
    6.10.2014
    There is actually a 3rd "table" and that sort of connects the two and that is stock on hand per art. code.
    The main issue is that stock is assigned to purchase orders only when it actually arrives in the warehouse.
    A human can easilly connect the dates of when the stock will arrive and quantities with correct customer's order. In this case the firts order will get 50 pcs in August while 10 pcs will remain on backorders. The missing 10 pcs Will arrive in October. The second order will get 10 pcs in october and 3 will remain on backorders with no delivery date. While the third customer orders does not have a delivery date.
    So how to make the SAP do this calculations and display the arrival date next to date of customer's order?

    I checked the instructions as i do not have access to this part. It seem this is a query. We had issues with queries in the past as not all codes from orders would appear in them. They never found the reason why that is happening.
    However, I think the main issue is that the information here is not connected and is separately provided for supply and for sales. So i doubt it can be connected in this query.
    edit: as you can see the only connection is stock on hand.
    and total number of various items we have is close to 100.000 of various article codes.

  • How to join two tables using EJB-QL

    Hi There,
    How to join tables using EJB-QL ?
    Thanks.
    Edited by: vamseebobby on Nov 6, 2007 8:12 AM

    You might try
    SELECT b.entity2property FROM Entity1 a JOIN a.entity2 b
    for example, to retrieve players names, from a Players table, that belong to the team 'My Team' in the Teams table
    SELECT b.playerName FROM Teams a JOIN a.players b WHERE a.teamName = 'My Team'

  • How to join two crosstabs such that they appear as one?

    Hi
    I tried to join two cross tabs such that they appear to be one. I tried the format the view of the cross tabs by setting the value of top and bottom padding as zero but it is not working. It is taking some default space between the cross tabs.
    Is it possible to join the crosstabs?
    Thanks
    Jasleen

    I set the wrong case .my question has been answered..
    Thank you ~
    Edited by: Richard 1982 on 2009-12-27 下午9:55

  • How to join two tables in a cursor

    i have a cursor that selects data from one table,
    i want it to select data from one other table also.. how i can do that.. is there any alternate way to do that if yes then suggest .. waiting for ur reply....

    employee_number" and other has column name as "comp_employee_number" .. Well that would be quite simple ....
    SELECT e1.foo, e2.bar 
    FROM   employees e1, staff_members e2
    WHERE e1.employee_number = e2.comp_employee_number;.... unless what you're really expecting is for the datbase to somehow figure out by itself that although those columns have different names they actually represent the same data and magically derive the join for you.
    Perhaps, you really need to explain in more detail precisely what your problem is.
    Cheers, APC

  • How to join two tables without constraints??

    I want get the tables to be joined without constraints!!
    table1 :
    100     get
    101     wet
    102     set
    and
    table 2 :
    10     xxx
    11     yyy
    12 zzz
    I got the output like this,
    output :
    ID NAME ID NAME
    101     wet     10     xxx
    101     wet     12     zzz
    101     wet     11     yyy
    100     get     10     xxx
    102     set     11     yyy
    102     set     10     xxx
    100     get     11     yyy
    100     get     12     zzz
    102     set     12     zzz
    but i want everything to be written once.
    Help me out with this!!???

    Tanx fr the response!
    Nah, but me used toad to run it. And my query is
    QUERY 1 :
    SELECT * FROM PARTES P,CUSTES C
    WHERE (P.ID,P.NAME,C.ID,C.NAME) IN (SELECT P1.ID,P1.NAME,C1.ID,C1.NAME
    FROM PARTES P1,CUSTES C1)
    QUERY 2 :
    select id as pid, name as name from partes
    union
    select id as pid,name as name from custes;
    OUTPUT FOR QUERY2 IS,
    PID NAME
    10     xxx
    11     yyy
    12     zzz
    100     get
    101     wet
    102     set
    In the 2nd query am getting the joined records of both the tables. But my need is both the tables record to be displayed like this
    ID NAME ID_1 NAME_1
    10     xxx 100     get
    11     yyy 101     wet
    12     zzz 102     set
    What i am trying is,i want to join the all the columns parallely in my output!!
    Is there any source mike?

  • How to join two tables using UD Connect ?

    Hi,
    I have 2 tables on which I need to create join & extract the data from Oracle database using UD connect. Is this possible? If yes, please let me know how or suggest an alternative approach.
    Thanks,
    Sunil

    Thanks Tony for the reply..  Actually, the issue is Netweaver Java dictionary doesn't allow you to create a view, right? Also, I dont want to create a view directly on the database.
    I want to handle this on BI side somehow.

  • How can join two tables if column values does not match

    Hi guys,
    i have table
    col1 col2
    abcd 123
    asdf 234
    wert 456
    sedf 789
    and another table with
    col1
    abcd
    aaaa
    but i need the output like
    abcd 123
    abcd 234
    abcd 456
    abcd 789
    aaaa 123
    aaaa 234
    aaaa 456
    aaaa 789

    You do not tell us about this where condition before, but...
    select b.col1, a.col2  from table a, another_table b
    where a.col2 in (123, 234, 456, 789)or
    select b.col1, a.col2  from table a, another_table b
    where a.col1 in ('abcd','asdf','wert','sedf' )

  • Outer Join Two tables

    I got two Tables.APPROVAL_ROUTING_TAB and doc_issue_tab where APPROVAL_ROUTING_TAB has more rows. I need to do the join two tables such that All the rows in APPROVAL_ROUTING_TAB should be displayed ( more rows) but still connect with the doc_issue_tab. I did an outer join syntax failed.
    What is the correct syntax for this.
    Key_ref takes the following pattern "DOC_CLASS=PR_CLASS_1^DOC_NO=1000007^DOC_REV=A3^DOC_SHEET=1^"
    SELECT
    ar.line_no LINE_NO,
    ar.step_no STEP_NO,
    ar.lu_name LU_NAME,
    ar.key_ref KEY_REF,
    ar.description DESCRIPTION,
    di.status STATUS
    FROM APPROVAL_ROUTING_TAB ar, doc_issue_tab di
    WHERE
    ar.key_ref = 'DOC_CLASS='||di.doc_class||'^DOC_NO='||di.doc_no||'^DOC_REV='||di.doc_rev||'^DOC_SHEET='||di.doc_sheet||'^') (+)
    Thansk in advance
    Prash

    Other options include:
    with t1 as (select 1 id, 'd1=fred^d2=john^d3=bob^' col2 from dual union all
                select 1 id, 'd1=fred^d2=john^d3=george' col2 from dual),
         t2 as (select 'fred' d1, 'john' d2, 'bob' d3 from dual union all
                select 'jim' d1, 'john' d2, 'bob' d3 from dual)
    select *
    from   t1, (select t2.*, 'd1='||d1||'^d2='||d2||'^d3='||d3||'^' full_col
                from t2) t3
    where  t1.col2 = t3.full_col (+);
            ID COL2                      D1   D2   D3  FULL_COL              
             1 d1=fred^d2=john^d3=bob^   fred john bob d1=fred^d2=john^d3=bob^
             1 d1=fred^d2=john^d3=george                                     
    with t1 as (select 1 id, 'd1=fred^d2=john^d3=bob^' col2 from dual union all
                select 1 id, 'd1=fred^d2=john^d3=george' col2 from dual),
         t2 as (select 'fred' d1, 'john' d2, 'bob' d3 from dual union all
                select 'jim' d1, 'john' d2, 'bob' d3 from dual)
    select *
    from   t1 left outer join t2 on (t1.col2 = 'd1='||d1||'^d2='||d2||'^d3='||d3||'^');
            ID COL2                      D1   D2   D3
             1 d1=fred^d2=john^d3=bob^   fred john bob
             1 d1=fred^d2=john^d3=george             

  • Join two tables which stored in difference database

    Hi, i have a problem how to join two tables which are stored in difference databases. I'm using MS access and need to use Jsp to solve it. is anyone have idea to solve it. thxx

    Hi,
    I think you cannot join the tables which are in two diff databases. You have to connect to each database ,get the result and manipulate in your program. Use a bean.
    cheers,
    Narayana

  • Join two table (Inner Join)

    how to join two tables using inner join.

    Tariq,
    Pretty vague question.  You can create joins in an ABAP program, or while creating a view, or when creating a SAP query of one type or another.  Some people download tables and then join them using desktop software.  If you can elaborate your question I may be able to give you a better answer.
    I recently joined two wooden tables at a picnic.  I used 24 gauge galvanized wire combined with duct tape, so I guess you couldn't really call that an 'inner join'.
    Best Regards,
    DB49

  • Want to Join two tables with cursors

    Can anyone tell me how to join two tables only by cursors.
    Not with:
    1.Joining condition
    2.Procedure etc.
    Only cursors with passing parameters.
    Sowmya

    This is my assignment. I want to get the matching records from both tables. I have pk, fk for both tables for deptno.Can I pass parameter for this.
    dept table:
    deptno deptname
    10 sales
    20 Erp
    30 hr
    40     marketing
    emp table:
    Empno deptno Name
    1 10 lee
    2 20 hans
    3 10 peter
    4 30 james
    5 30 king
    Output should be:
    deptno empname empno deptname
    10 lee 1 sales
    10 peter 3 erp
    30 james 4 hr
    30 king 5 marketing

Maybe you are looking for

  • I upload songs, but they dont show up on my ipod?

    i have used itunes to upload my CDs and downloaded songs onto my ipod, i click the update ipod button and itunes SAYS its importing them to the ipod, but i disconnect and there is still nothing on it. Does anyone know what im doing wrong?

  • PO confirmation

    Hi Experts, Is it possible to enter a confirmation at item level instead of at schedule line level? If yes is there anything specific that needs to be configured? Thanks!

  • Encore update download error

    In process of downlaoding Encore update, error U43M1D207 occuered and the download was unsuccessful. Any suggestions?

  • Windows setup could not configure windows to run on this computer hardware

    As I was trying to reinstall win 7 on my HP Pavilion dv6-7028tx Enterta laptop, upon competition, I was given this message by win7 saying that " windows setup could not configure windows on this computer's hardwear".  I did some research on this issu

  • FLV files without sound

    Hi, When I try to play some flash video files from youtube, google video or the ones I make, the video plays ok, but the sound not. This happens with all the browsers I have installed (Safari, Firefox, Camino, Opera). Any guess what could be? Thanks,