So that to joining 3 tables make me 2 ranks, real, I need only one line

Hi all

While joining 3 tables make me 2 rows, I need 1 row.

Please find my request and the actual output and the expected results.

Help me handle this.

Select

-MFU_D_C_INVESTOR_ID_DET,

mfu_remove_junk (Q.CAN) CAN_ST,

mfu_remove_junk (Q.INSTALLMENT_AMOUNT) AMOUNT_ST,

mfu_remove_junk (x.Can) can be,

mfu_remove_junk (x.Amc_Code) Amc_Code,

mfu_remove_junk (x.Folio_No) Folio_No,

mfu_remove_junk (x.Order_Status) Order_Status,

mfu_remove_junk (x.User_Code) User_Code,

mfu_remove_junk (x.User_Txrn_No) User_Txrn_No,

mfu_remove_junk (x.Group_Ord_No) Group_Ord_No,

mfu_remove_junk (x.Ind_Txn_Ref_No) Ind_Txn_Ref_No,

mfu_remove_junk (x.Pending_Txn_Ref_No) Pending_Txn_Ref_No,

mfu_remove_junk (x.Appl_No) Appl_No,

mfu_remove_junk (x.Ts_Machine_Id) Ts_Machine_Id,

mfu_remove_junk (x.Trxn_Date) Trxn_Date,

mfu_remove_junk (x.Trxn_Time) Trxn_Time,

mfu_remove_junk (x.Timestamp_No) Timestamp_No,

mfu_remove_junk (x.Sch_Code) Sch_Code,

mfu_remove_junk (x.Reinv_Tag) Reinv_Tag,

mfu_remove_junk (x.Txn_Mode) Txn_Mode,

mfu_remove_junk (x.Trxn_Type) Trxn_Type,

mfu_remove_junk (x.Sub_Trxn_Type) Sub_Trxn_Type,

mfu_remove_junk (x.Units) units,

mfu_remove_junk (x.Amount) amount.

mfu_remove_junk (x.All_Units_Flag) All_Units_Flag,

Entity_Id, mfu_remove_junk (x.Entity_Id),

mfu_remove_junk (x.ENTITY_BRANCH_ID) ENTITY_BRANCH_ID,

mfu_remove_junk (x.Location) location,

(TO_CHAR(sysdate,'DD-MON-RRRR'))        CREATED_DATE

Of MFU_FTP_XML_FILES T

Left Join Xmltable ('/ COMM_TXN_STRUCT/FILE_ROWS/FILE_ROW ')

By the way T.Filecontent

Columns

-MFU_D_C_INVESTOR_ID_DET

Can Varchar2 (500) path ' INVESTOR_ID_DET / CAN'.

Path of Varchar2 (500) Amc_Code "INVESTOR_ID_DET/AMC_CODE,"

Path of Varchar2 (500) Folio_No "INVESTOR_ID_DET/FOLIO_NO,"

Path of Varchar2 (500) Order_Status ' TRANSACTION_DET/ORDER_STATUS. "

Path of Varchar2 (500) User_Code "TRANSACTION_DET/USER_CODE,"

Path of Varchar2 (500) User_Txrn_No "TRANSACTION_DET/USER_TXRN_NO,"

Path of Varchar2 (500) Group_Ord_No "TRANSACTION_DET/GROUP_ORD_NO,"

Path of Varchar2 (500) Ind_Txn_Ref_No "TRANSACTION_DET/IND_TXN_REF_NO,"

Path of Varchar2 (500) Pending_Txn_Ref_No "TRANSACTION_DET/PENDING_TXN_REF_NO,"

Path of Varchar2 (500) Appl_No "TRANSACTION_DET/APPL_NO,"

Path of Varchar2 (500) Ts_Machine_Id "TRANSACTION_DET/TS_MACHINE_ID,"

Path of Varchar2 (500) Trxn_Date "TRANSACTION_DET/TRXN_DATE,"

Path of Varchar2 (500) Trxn_Time "TRANSACTION_DET/TRXN_TIME,"

Path of Varchar2 (500) Timestamp_No "TRANSACTION_DET/TIMESTAMP_NO,"

Path of Varchar2 (500) Sch_Code "TRANSACTION_DET/SCH_CODE,"

Path of Varchar2 (500) Reinv_Tag "TRANSACTION_DET/REINV_TAG,"

Path of Varchar2 (500) Txn_Mode "TRANSACTION_DET/TXN_MODE,"

Path of Varchar2 (500) Trxn_Type "TRANSACTION_DET/TRXN_TYPE,"

Path of Varchar2 (500) Sub_Trxn_Type "TRANSACTION_DET/SUB_TRXN_TYPE,"

Units Varchar2 (500) Path TRANSACTION_DET/UNITS"."

Amount Varchar2 (500) path ' TRANSACTION_DET/AMOUNT. '

Path of Varchar2 (500) All_Units_Flag "TRANSACTION_DET/ALL_UNITS_FLAG,"

Path of Varchar2 (500) Entity_Id ' TRANSACTION_DET/ENTITY_ID. "

Path of Varchar2 (500) ENTITY_BRANCH_ID "TRANSACTION_DET/ENTITY_BRANCH_ID,"

Path of Varchar2 (500) "TRANSACTION_DET/RENTAL.

) X

(1 = 1)

the left join XMLTABLE ('/ CT_SYS_STRUCT/FILE_ROWS/FILE_ROW ')

PASSAGE T.FILECONTENT

columns

CAN varchar2 (500) PATH ' INVESTOR_ID_DET / CAN'.

INSTALLMENT_AMOUNT varchar2 (500) PATH "TRANSACTION_DET/INSTALLMENT_AMOUNT".

) Q

(1 = 1)

Where

TRUNC ((TO_DATE (T.RETRIVED_DATE, 'DD-MON-RRRR HH PM'))) = TRUNC(SYSDATE-2)

Order By X.Can Asc, Rownum;

O/P: real

15114LBA01 1000.00 (null) (null) (null) (null) (null) (null) (null)

(null)      (null) 15114LBA01 SMF AC UGM 40715117000 15114010001 1511401000102

O/P: expected

amount can_st peut amc command user trxn_no group_ord ind_txn_no

1000.00 15114LBA0115114LBA01 SMFCA40715117000 15114010001 1511401000102 UGM

It would have been helpful if you had your more detailed condition described in brief.

For as far as I understand nothing xmldata in every line of MFU_FTP_XML_FILES can you wheter structure COMM_TXN_STRUCT or CT_SYS_STRUCT.

So what about something like below

Select

x.*

, q.*

sysdate

de)

Select

x.cols

MFU_FTP_XML_FILES t

, Xmltable ('/ COMM_TXN_STRUCT/FILE_ROWS/FILE_ROW ')

By the way T.Filecontent

Columns

the_x_cols

) x

Where

TRUNC ((TO_DATE (T.RETRIVED_DATE, 'DD-MON-RRRR HH PM'))) = TRUNC(SYSDATE-2)

) x

Join

-a full outer join if there are cans without match

(

Select

q.cols

MFU_FTP_XML_FILES t

, XMLTABLE ('/ CT_SYS_STRUCT/FILE_ROWS/FILE_ROW ')

PASSAGE T.FILECONTENT

columns

CAN varchar2 (500) PATH ' INVESTOR_ID_DET / CAN'.

INSTALLMENT_AMOUNT varchar2 (500) PATH "TRANSACTION_DET/INSTALLMENT_AMOUNT".

) q

Where

TRUNC ((TO_DATE (T.RETRIVED_DATE, 'DD-MON-RRRR HH PM'))) = TRUNC(SYSDATE-2)

) Q

on (x.can = q)

Order By X.Can Asc, Rownum;

Tags: Database

Similar Questions

  • table is expected to insert only one line

    Hi all

    my need is to create the table that allows to insert only one line.

    How can I make it?

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    PL/SQL Release 11.2.0.1.0 - Production

    "CORE 11.2.0.1.0 Production."

    AMT for Linux: Version 11.2.0.1.0 - Production

    NLSRTL Version 11.2.0.1.0 - Production

    Hello

    2621671 wrote:

    Hi all

    my need is to create the table that allows to insert only one line.

    How can I make it?

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    PL/SQL Release 11.2.0.1.0 - Production

    "CORE 11.2.0.1.0 Production."

    AMT for Linux: Version 11.2.0.1.0 - Production

    NLSRTL Version 11.2.0.1.0 - Production

    You can create a unique Index based on a function, like this:

    CREATE UNIQUE INDEX table_x_u ON table_x (NVL2 (col_1, 1, 1));

    You can use any column of any data type.  In other words, the function may return a NUMBER, if the column referenced in the function is a NUMBER.

    Regardless of whether the column is NULL or not; not more than 1 rank is authorized.

  • I need to create a table of contents in iPages but I want only one word for the title, not the line of holes. Or, how can I change the contents of the table? Thank you!

    I need to create a table of contents in iPages but I want only one word for the title, not the line of holes. Or, how can I change the contents of the table? Thank you!

    Yes, you can have a one word title, by assigning a paragraph style title to this one word. No, you cannot change the text in a Table of contents, but you can change paragraph style font attributes (line) and add for example, a head of points between the types of OCD paragraph and page numbers. No part of the table of contents will not provide hyperlinks in exported PDF documents.

    When you look up in the menu bar, you can see the word iPages, or simply Pages. There is no product of iPages.

  • How can I change the automatic country setting that is displayed in the payment gateway billing address? There is only one country in the drop-down list, not my current country

    How can I change the automatic country setting that is displayed in the payment gateway billing address? There is only one country in the drop-down list, not my current country

    A few changes/Verify account https://forums.adobe.com/thread/1465499 links that can help

    -html http://helpx.adobe.com/x-productkb/policy-pricing/change-country-associated-with-adobe-id.

  • Mobile navigation - drop-down menu that closes after click and scroll to anchor? Am I the only one looking for this feature?

    Well, the question is a bit in the subject:

    But the problem is that I have a Compostion Widget with a menu inside. On my phone a tab in the menu opens - click on a menu item scrolls to the anchor - but the menu keep an open - I want it closes! So if you need to go to a new anchot - you open the new menu etc.

    How do I do that?

    BR,

    Mike

    Hi Mike,.

    Please make sure you have selected options as follows in the drop of the composition:

    Kind regards

    Akshay

  • Opening browser indicates that master and all versions: how to go back to the list only one version?

    Opening 3.6: in some way something changed: in the browser, I see now several versions of each image (master & version), how to get back to showing only latest version? (Note: I don't want close chimneys, just not to show them)

    You have recently allowed the preference of the opening > advanced: create new versions adjustments?

    The opening will create a new version whenever you adjust your image.  With this preference is disabled, all changes will be stacked on the current version without creating new versions.

    You can stack the new versions automatically if you use "opening > General > stacking new versions automatically.

    But there is no option to avoid the multiple versions of a photo in the browser, as far as I know, so the battery version is open.  You can stack several version and keep the closed stack or refrain from creating new versions for each change.

  • Problem with headphone selection if the table has only one row

    Hi all

    I have developed a table in which I use selection listener to perform a task when a line is selected.
    It works fine when I have more than 1 row in the table, but when I did that one line in the table, the listener of selection do not call the corresponding method in the bean.
    I understand this selection event is raised only when the line is changed, but in the case of use when only one line is there, what do I do to make the listener of selection work?

    The selection listener I wrote the code to make the line selected as current line and perform the required task.

    Please suggest a way out of this situation.

    Thanks in advance.

    Hello

    try to remove this table attr

    selectedRowKeys="#{bindings.xxx_VO1.collectionModel.selectedRow}"
    
  • Is it possible to select only one column of a table for the redaction?

    Hi, converted a Word doc with a table in PDF format.  You will need to write a single column of the table.

    Is it possible to select only one column for the redaction?  When we select and drag downwards, it selects the other columns in the following lines.

    With the help of Acrobat X Pro.  Any help is appreciated.

    Hold down the CTRL key and drag a selection.

  • Join the tables in the responses

    I would like to know if it is possible to join the tables together as below in the answers?

    Select a.Field1, b.Field1
    FROM tableA an outer join left tableA b on
    a.Field1 = b.Field

    If you want to make an INNER JOIN, and then type INNER JOIN instead of LEFT INNER JOIN.

    If you want to left outer join and LEFT OUTER JOIN instead of INTERNAL LEFT JOIN type.

    Nothing asked as a left inner join. That is why it gives error + [nQSError: 27002] near +.

    Thank you

  • Help on a join of tables

    Hello

    I am trying to write a join on some tables, but can't seem to make it work. The selection criteria are:

    Table A: Master
    Columns: Name, location

    Table b: permissions
    Columns: Name, location

    I need to select the combination of the name, location and compare this combo against B the Table name, location. I need to return the name, the combination of location on the Board where this combination does not exist in Table B.

    Here is an example:

    Table A

    Name: location:
    John U.S.
    Phil U.S.
    John UK


    Table B

    Name: location:
    John U.S.
    Phil U.S.


    John-> UK exist in the table B, so need to return this combination.

    Any help we appreciated, thanks!

    Hello

    Here's a way to do this with a join:

    SELECT     *     -- Or whatever columns you want
    FROM          a
    LEFT OUTER JOIN     b  ON     a.name          = b.name
                         AND     a.location     = b.location
    WHERE   b.name        IS NULL
    ;
    

    In case you like jargon, joining the 2 tables, but only selection of columns of one of them is called a semi Join .

    Include other ways to achieve the same results
    LESS
    a NOT IN subquery
    a NOT EXISTS subquery

    The query above assumes that if the two tables have a NULL value in a column, then you don't want to consider these lines are the same.
    If you don't want to consider the same thing, then:

    SELECT     *
    FROM          a
    LEFT OUTER JOIN     b  ON     'x' || a.name          = 'x' || b.name
                         AND     'x' || a.location     = 'x' || b.location
    WHERE   b.ROWID        IS NULL
    ;
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • Joining MySQL Tables

    I have a MySQL table that contains two user, each a different user id. I want to make a query that joins the table containing the table user to retrieve user names corresponding to these two user id how is this possible?

    "AngryCloud" wrote in message
    News:fgg691$1JT$1@forums. Macromedia.com...
    > Sorry, I do not think that my question I explained that well. Let me rephrase:
    >
    > I have a MySQL table that contains two user id, each other
    > user.
    > Each of the id is in another column. I want to make a query that
    > joins
    > user table that contains the table to retrieve the corresponding user names to the
    > time
    > user
    >
    > Lets say I have a table called Messages. A record in the salons of tables the
    > ID recipient is 26 'and the sender ID is 14'. I want to create a query
    > who
    > joins the table of Messages containing the data of the user table to get the names of users of
    > each
    > these users.
    >
    > Just for possible yet understand, let me show you an example query
    > who
    > doesn't make any sense, but it might be useful to describe what I'm trying
    > reach.
    >
    > 'SELECT messages.recipient_id, messages.sender_id, messages.message,
    > user_data.username
    > MESSAGES
    > User_data LEFT JOIN ON messages.recipient_id = user_data.id
    ' > User_data LEFT JOIN ON messages.sender_id = user_data.id.

    in fact it makes sense, but you must apply aliases for tables
    and columns

    SELECT messages.recipient_id, messages.sender_id, messages.message,
    recipient_data. UserName as beneficiary, sender_data.username as sender
    ((MESSAGES
    User_data LEFT JOIN AS recipient_data ON messages.recipient_id =
    USER_DATA.ID)
    User_data LEFT JOIN AS sender_data ON messages.sender_id = user_data.id)

  • Join the table orders from clause

    Hi all

    Who is the effective way to join the tables in from clause. I have two tables first with 20 lakh records and second containing 10 lakh recods.
     
    QUERY 1:  SELECT T4.ID,T4.ISO_NAME  FROM T,T4 
    WHERE T4.ISO_NAME LIKE '%US%' AND T.ID=T4.ID;
    
    QUERY 2:  SELECT T4.ID,T4.ISO_NAME  FROM T4,T 
    WHERE T4.ID=T.ID AND  T4.ISO_NAME LIKE '%US%';
    
    T(ID IS PRIMARY KEY) 
    (20 lakh records)
    
    T4 (ID IS PRIMARY KEY ) 
    (10 lakh records)
    ---------------------
    ID     ISO_NAME
    100  US,UK,IN,BR
    101  UK,US,BR,IN
    102  BR,UK,US,IN
    
    
    Note: No index on ISO_NAME .
    Who is the effective query 1 or 2. Please suggest me if you have an idea to rewrite the query.



    Kind regards
    Rajasekhar

    Published by: SuNRiZz68 on January 29, 2009 04:22

    In practical terms, Alex is right. Sometimes it matter what table is selected first, but does the CBO generally a very good job of deciding what you need to select the first (assuming that your statistics are up to date) but this is the situation you are trying to avoid as much as possible.

    If you specify a table main command tables in the clause is not reliable and should be used - but think before using advice and don't do that when necessary.

    Which table to select depends firstly on the join method in the execution plan. Nested loops joins perform better by selecting in the smaller table first, make a loop on the largest table. Joins the smaller set hash table in memory first, and then go through the larger table, perform searches in memory. He can't make any difference, what table is read using first the merger joins and sort.

    Back to your original question. Using the cost-based optimizer, both queries will probably roll the same because newer versions of Oracle (9i, 10g) often transform queries for efficiency before the execution anyway. According to what do you or do not request should probably run a nested loop or hash join. With a small set of data creaing index and using a search of nested loops will probably be faster to avoid full table scans. the '%' in the LIKE clause leader would ignore an index on the ISO_NAME column in any case if a main column may be used in a composite index. All this is based on the approximation using the information provided; Tuning questions should always be tested to unexpected developments.

  • joining several tables to generate data

    with itemlist as

    (select 1 cid, listname 'test', 'r' flg Union double all the)

    Select 2 cid, listname 'test2', ' not flg double

    ),

    category 1)

    Select 1 cid, 122 k' sub '123' catcode, of any double Union

    Select 1 cid, '234i' catcode, sub '124' all Union double

    Select 1 cid, 238 k' void '124' catcode, double

    )

    void)

    Select 1 cid, sub '123' of any union double

    Select 1 cid, sub ' 124' double

    )

    I want to write a static query that gathers all the tables and produces the following output assuming that

    CID is you pass as a parameter

    CID listname flg topic catcode

    1 123 122 k r test

    1 test of r 234i 124

    1 124 238 k r test

    Suppose the data as changes to follow and even cid 1 is to pass as a parameter:

    with itemlist as

    (select 1 cid, listname 'test', 'r' flg Union double all the)

    Select 2 cid, listname 'test2', ' not flg double

    ),

    category 1)

    Select 1 cid, 122 k' sub '123' catcode, of any double Union

    Select 1 cid, '234i' catcode, sub '124' all Union double

    Select 1 cid, 238 k' void '124' catcode, double

    )

    void)

    Select 2 cid, sub '123' of any union double

    Select 2 cid, sub '124' double

    )

    then the output should be

    CID listname flg topic catcode

    1 r test 123

    1 test of r 124

    1 test of r 124

    for a final example, suppose the data now as to user 1 as cid

    with itemlist as

    (select 1 cid, listname 'test', 'r' flg Union double all the)

    Select 2 cid, listname 'test2', ' not flg double

    ),

    category 1)

    Select 2 cid, 122 k' sub '123' catcode, of any double Union

    Select 2 cid, catcode '234i', '124' void in any union double

    Select 2 cid, 238 k' void '124' catcode, double

    )

    void)

    Select 1 cid, sub '123' of any union double

    Select 2 cid, sub '124' double

    )

    output must be

    CID listname flg topic catcode

    1       test            r                 123

    Basically, the user will pass a cid, in this case 1. I'll read the itemlist where cid = 1 and I want to join all the other tables

    to itemlist in such a way that I can generate extra lines.  If no entry is found for cid 1, for example, in category 1 or auxiliary table

    then the beloging column of this table must be null in the result

    can someone help me write a query to produce the output above

    Hello

    elmasduro wrote:

    ...

    Here is an explanation of the output.  a user will have a front screen where it can enter itemlist info.
    then in a submenu may enter a category or sub or both or none of them. the user can select multiple categories or sub
    When the user presses the button Save, an entry will be made in the itemlist table, for example the cid = 1.
    If he choose a category but without Subs, then will be entered into the table at say cid = 1


    but no entries will be made for sub because he chose not to all values.  If he chooses void instead of category values
    then sub taable will fill and category is not. If he chooses the category and under, then both will be filled.

    what I want to do is to join the itemlist with table category and sub table and get the data to the Scriptures, this intervention of the user.
    These entries not found will be the null value column in the result.
    for example, the cid = 1 itemlist, if user enter category but not void, itemlist will be the join with the table category and sub
    but since sub has no entry for the cid = 1, the column object will be empty in the output, but catcode will fill

    I'm so confused.

    It is a query (that is, just a SELECT statement, which shows the data already present in the tables), or is this a DML statement, that will add data to the tables?  If it's just a query, then do not say things like "entries will be taken" or "filled with tables.

    Assuming you want a request maybe you want something like this:

    WITH c_and_s AS

    (

    SELECT NVL (c.cid, s.cid) AS cid

    NVL (c.sub, s.sub) AS topic

    , NVL2 (s.cid, c.catcode, NULL) AS catcode

    CATEGORY 1 c

    FULL OUTER JOIN void s ON c.cid = s.cid

    AND c.sub = s.sub

    )

    SELECT i.cid, i.listname, i.flg

    cs.subject, cs.catcode

    Itemlist I have

    LEFT OUTER JOIN c_and_s ON cs.cid = i.cid cs

    WHERE the i.cid (1) - you can do the cids 2 or several at the same time, if you want to

    ORDER BY i.cid, cs.subject, cs.catcode

    ;

    This example gets the output you asked data sample you posted.

  • Join several Tables versioned

    Hello

    We are working on a data warehousing project and wonder how do to join several tables that each are versioned separately (type SCD 2 with a valid and valid to date).

    Because for example, we get our client from a single source of information (id customer, name, etc.) and the information on the rate of customer from another source.  The sources are different, we have the separate tables for them and each of them gets versioned independently.

    Here's my customer table (with its own valid and valuable to the columns).

    IDName of the customerValid fromValid until the
    1CitiBank1 JANUARY 14JANUARY 1, 15
    1New CitiBank2 JANUARY 15FEBRUARY 1, 15
    1Latest CitiBank2 FEBRUARY 15APRIL 1, 15

    And similarly the Client side ID and rating information.

    IDNoteValid fromValid until the
    1Platinum1 JANUARY 14FEBRUARY 1, 14
    1PremiumFEBRUARY 1, 141ST MARCH 15

    I want to merge the two tables above and present information at a glance.  I have some difficulty to determine validates the valid columns.

    IDName of the customerNoteValid from (Calculated)Valid until the (calculated)
    1CitiBankPlatinum1 JANUARY 14FEBRUARY 1, 14
    1CitiBankPremiumFEBRUARY 1, 14JANUARY 1, 15
    1New CitiBankPremium2 JANUARY 15FEBRUARY 1, 15
    1Latest CitiBankPremium2 FEBRUARY 151ST MARCH 15

    And it's the query I used to get the above result:

    SELECT client. id ,

           customer . name ,

           CRM . level ,

           Greatest (client. vld_fm , crm. vld_fm ),

           Least (client. vld_to , crm. vld_to )

    DE    client client,

           client_rating crm

      client. id = crm. id

           AND ( client. vld_fm <= crm. vld_fm

                 AND client. vld_fm <= crm. vld_to

                 AND client. vld_fm >= crm. vld_fm

                 AND client. vld_fm >= crm. vld_to )

            OR ( client. vld_fm BETWEEN crm. vld_fm AND crm. vld_to )

            OR ( client. vld_to BETWEEN crm. vld_fm AND crm. vld_to );



    The problem is we have several data sources (and each with its own versions) and joins become so very very complex.  Is there a better way to write the query?

    Or maybe a better way to design our tables?

    Thanks for your help.

    Anand

    Hello

    you only need ranges that overlap to join.

    Re: How do to sql query in a loop

    Is a simpler way to test if the x_start to x_stop range comes into conflict with the range of y_start to y_stop

    WHERE     x_start <= y_stop AND     y_start <= x_stop
    

    In other words, two overlapping if and only if everyone will start before the other ends one. If this is not obvious (and it was certainly not clear to me when I heard it), then look at it this way: two ranges are not overlapping if and only if one of them starts after the end of the other.

    Concerning

    Marcus

  • JOIN the question... Join two tables without omitting lines

    I came across a problem that should be an easy fix (I hope), but I'm having a hard time to come up with a solution.

    Basically I have two tables, one with the actual amounts with the budget. I have to write a sql statement select that joins these tables together and includes all of their lines. I was able to join the tables by using JOIN, LEFT JOIN and RIGHT JOIN, but it always fails the lines I need.

    Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity, I built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables are not quite that simple, but I don't think it was relavent to this issue.

    AMOUNT_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT

    2013

    111111555555000010020131111115555551000100201311111155555520001002013111111555555300010020131111115555554000100

    BUDGET_TABLE

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT BUDGET

    2013

    1111115555553000200201311111155555540002002013111111555555500020020131111115555556000200

    Here's what I hope. Note that SUB_ACCOUNTs 0000, 1000, and 2000 show without budget amounts since there is not a corresponding line in the BUDGET_TABLE. And same for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amount because there is not a corresponding line in the AMOUNT_TABLE.

    (exit)

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    201311111155555500001000
    201311111155555510001000
    201311111155555520001000
    20131111115555553000100200
    20131111115555554000100200
    201311111155555550000200
    201311111155555560000200

    If all goes well, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.

    Use the join ANSI - FULL OUTER JOIN syntax:

    with amount_table like)

    Select fiscal_year 2013, 1 period, 11111 acct_unit, 555555, 0000 sub_account, amount 100 of all the double union

    Select 2013,1,11111,555555,1000,100 from all the double union

    Select 2013,1,11111,555555,2000,100 from all the double union

    Select 2013,1,11111,555555,3000,100 from all the double union

    Select double 2013,1,11111,555555,4000,100

    ),

    budget_table like)

    Select 1 time, 11111 acct_unit, account 555555, sub_account 3000, 2013 fiscal_year, budget of 200 Union double all the

    Select 2013,1,11111,555555,4000,200 from all the double union

    Select 2013,1,11111,555555,5000,200 from all the double union

    Select double 2013,1,11111,555555,6000,200

    )

    Select nvl (a.fiscal_year, b.fiscal_year) fiscal_year,

    period of NVL (a.period, b.period),

    NVL (a.acct_unit, b.acct_unit) acct_unit.

    account of NVL (a.Account, b.Account),

    NVL (a.sub_account, b.sub_account) sub_account.

    Amount NVL(a.amount,0),

    NVL(b.budget,0) budget

    of amount_table one

    full join

    budget_table b

    on)

    a.Fiscal_Year = b.fiscal_year

    and

    a.period = b.period

    and

    a.acct_unit = b.acct_unit

    and

    a.Account = b.account

    and

    a.sub_account = b.sub_account

    )

    /

    FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
    ----------- ---------- ---------- ---------- ----------- ---------- ----------
    2013 1 11111 555555 0 100 0
    2013 1 11111 555555 1000 100 0
    2013 1 11111 555555 2000 100 0
    2013 1 11111 555555 3000 100 200
    2013 1 11111 555555 4000 100 200
    2013 1 11111 555555 6000 0 200
    2013 1 11111 555555 5000 0 200

    7 selected lines.

    SQL >

    SY.

Maybe you are looking for