Find rows from a table with no Activities

Hi,
I have a ‘Data’ table in relation with a ‘Note’ table with a date and I would like to find all the rows in the ‘Data’ table that do not have any ‘Note’ taken in the the last 3 months (including no ‘Note’ at all)?
THanks,

Hi,
934281 wrote:
Thanks for the great and quick answers!
Could someone tell me what is the difference between the 2 methodes (Not Exist vs Not In)?They can usually be used to get the same results. Sometimes, it's easier to understand the logic of one rather than the other. Use whichever one you prefer. I can't guarantee that the optimizer won't do exactly the same thing, regardless of which one you use.
Also, I would I add in the Select the Date of the most recent Note and sort ASC so that I could have the Data that had not activity in the last 3 months and sorted by the one that had no activity the longest time ago first?In that case, I suggest a join, rather than either EXISTS or IN:
WITH     got_r_num     AS
     SELECT     d.*
     ,     n.notedate
     ,     ROW_NUMBER () OVER ( PARTITION BY  d.id
                               ORDER BY          n.notedate     DESC     NULLS LAST
                       )         AS r_num
     FROM           data        d
     LEFT OUTER JOIN      note        n  ON  n.dataid     = d.id
SELECT       *     -- Or list all couumns except r_num
FROM       got_r_num
WHERE       r_num          = 1
AND       NVL ( notedate
           , SYSDATE - 99     -- or any date more than 3 months ago
           ) <  ADD_MONTHS ( SYSDATE
                              , -3
ORDER BY  notedate
;If you'd care to post some sample data (CREATE TABLE and INSERT statements), and the results you want from that data, then I could test this.
When you say you don't want dates within the last 3 months, I assume you're including dates in the future. (Future dates may be impossible in your table, anyway.)
3 months can be as short as 89 days or as long as 92 days. I used ADD_MONTHS (sysdate, -3) to get exactly 3 months; you can use SYSDATE - 90 if that suits your needs.

Similar Messages

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • Join rows from 2 tables with non-matching numeric intervals

    Hi,
    Could you please help me with the following:
    I have 2 tables - [Coal_Samples] and [Coal Type] Which I have pasted below. I want to create a single result set that matches as closley as possible [Coal Type].Coal_Type to the interval between [Coal_Samples].mfrom and [Coal_Samples].mto. I would have
    [Coal_Samples] as the primary table using a left outer join.
    The problem is that the intervals [Coal_Samples].mfrom do not match [Coal Type].mfrom and [Coal_Samples].mto does not match [Coal Type].mto. I want to match the [Coal_Samples] intervals ([Coal_Samples].mfrom-[Coal_Samples].mto) as closely as possible to
    the [Coal_Type].Coal_Type field.
    I have been able to acheive this in excel using a VLOOKUP statement - but I want to know how to do this with and SQL Script without duplicating the rows based in [Coal_Samples].mfrom-[Coal_Samples].mto interval. 
    COAL SAMPLES TABLE
    ID
    mFrom
    mTo
    SAMPLE NUMBER
    AD261
    57
    57.5
    SAMPLE_001
    AD261
    57.5
    58
    SAMPLE_002
    AD261
    58
    59
    SAMPLE_003
    AD261
    59
    60
    SAMPLE_004
    AD261
    60
    61
    SAMPLE_005
    AD261
    61
    62
    SAMPLE_006
    AD261
    62
    63
    SAMPLE_007
    AD261
    63
    64
    SAMPLE_008
    AD261
    64
    65
    SAMPLE_009
    AD261
    65
    66
    SAMPLE_010
    AD261
    66
    67
    SAMPLE_011
    AD261
    67
    68
    SAMPLE_012
    AD261
    68
    69
    SAMPLE_013
    AD261
    69
    70
    SAMPLE_014
    AD261
    70
    71
    SAMPLE_015
    AD261
    71
    72
    SAMPLE_016
    AD261
    72
    73
    SAMPLE_017
    AD261
    73
    74
    SAMPLE_018
    AD261
    74
    75
    SAMPLE_019
    AD261
    75
    76
    SAMPLE_020
    AD261
    76
    77
    SAMPLE_021
    AD261
    77
    78
    SAMPLE_022
    AD261
    78
    79
    SAMPLE_023
    COAL   TYPE TABLE
    ID
    Type_mFrom
    Type__mTo
    COAL TYPE
    AD261
    57
    68.6
    BROWN COAL
    AD261
    68.6
    75
    GREY COAL
    AD261
    75
    78.2
    BLACK COAL
    AD261
    78.2
    79.2
    BLACK COAL
    Example   RESULT SET
    ID
    mFrom
    mTo
    DOMINANT_COAL TYPE
    AD261
    57
    57.5
    BROWN COAL
    AD261
    57.5
    58
    BROWN COAL
    AD261
    58
    59
    BROWN COAL
    AD261
    59
    60
    BROWN COAL
    AD261
    60
    61
    BROWN COAL
    AD261
    61
    62
    BROWN COAL
    AD261
    62
    63
    BROWN COAL
    AD261
    63
    64
    BROWN COAL
    AD261
    64
    65
    BROWN COAL
    AD261
    65
    66
    BROWN COAL
    AD261
    66
    67
    BROWN COAL
    AD261
    67
    68
    BROWN COAL
    AD261
    68
    69
    BROWN COAL
    AD261
    69
    70
    GREY COAL
    AD261
    70
    71
    GREY COAL
    AD261
    71
    72
    GREY COAL
    AD261
    72
    73
    GREY COAL
    AD261
    73
    74
    GREY COAL
    AD261
    74
    75
    GREY COAL
    AD261
    75
    76
    BLACK COAL
    AD261
    75
    76
    BLACK COAL
    AD261
    76
    77
    BLACK COAL
    AD261
    77
    78
    BLACK COAL
    AD261
    78
    79
    BLACK COAL
    Can you please help with the logic of this query?
    Thanks very much.

    Well, here is the beginning of the solution:
    ;with cte as (select S.*, T.[Coal Type] as [Dominant_Coal],
    case when 
    T.m_from between S.m_from and S.m_to
    AND T.m_to between S.m_from and S.m_to then 0
    when T.m_from between S.m_from and S.m_to then t.m_from - S.m_from
    else S.m_to - T.m_to end as [Diff]
    from Coal_Samples S LEFT JOIN Coal_Type T
    ON T.m_from between S.m_from and S.m_to
    OR T.m_to between S.m_from and S.m_to),
    cte1 as (select *, row_number() over (partition by cte.ID order by Diff) as Rn
    from cte)
    select * from cte1 where Rn = 1 -- attempt to get best match
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Select unique rows from two tables...

    Hi,
    I have two tables, replies1 and replies2.
    SQL> desc replies
    Name Null? Type
    URN VARCHAR2(36)
    ADDRESS VARCHAR2(18)
    FILESIZE NUMBER
    AS_NUM VARCHAR2(6)
    SQL> desc replies2
    Name Null? Type
    URN VARCHAR2(36)
    ADDRESS VARCHAR2(18)
    AS_NUM VARCHAR2(6)
    Both of the tables have no primary keys, but I have indixes on (urn, addrss) combination on both....
    I am trying to select the unique rows with (urn, address) from replies2, and then find the matching size from replies...
    I am using the following query:
    select distinct replies2.urn, replies2.address, replies.filesize from replies2, replies where replies2.AS_NUM like 'XYZ' and replies.urn = replies2.urn;
    I cannot figure out why it won't work. the way I understand it is that, distinct will give all distinct combination of all column names that follow, which is what I want...
    I know it is wrong, because the query:
    select count(*) from replies2 where AS_NUM like 'XYZ' returns less number of rows than the above query.
    Any help would be greatly appreciated.
    Thank you
    Oz.

    Thanks a lot Mohan for your reply.
    urn is not a unique key. Several rows could have the same (urn, address) pair in both tables. What I want is retrieve all (urn, address) rows from one table, and find the size from the other table to make a (urn, address, size). I want all unique combinations of (urn, address) to appear in the output.
    AS_NUM is an empty column in replies... It would've been a lot easier if it wasn't, since then I'll just say: select distinct urn, address, filesize from replies where AS_NUM like 'XYZ';
    I will try your query though and let u know how it goes. It takes quite a while to run since my tables are huge.

  • Need to remove duplicate rows from a table

    Hi Gurus ,
    I am using oracle 11.2.0.3 .
    SQL> desc osstage.S_EVT_ACT_X;
    Name                                      Null?    Type
    ROW_ID                                    NOT NULL VARCHAR2(15 CHAR)
    LAST_UPD                                  NOT NULL DATE
    PAR_ROW_ID                                NOT NULL VARCHAR2(15 CHAR)
    ATTRIB_17                                          NUMBER(22,7)
    ATTRIB_26                                          DATE
    ATTRIB_02                                          VARCHAR2(100 CHAR)
    PROCESS_TIMESTAMP                                  TIMESTAMP(6);
    now when i give the below command it gives the error as someone has disabled the constraint accidently .
    alter table s_evt_act_x enable constraint S_EVT_ACT_X_P1;
    Error starting at line 3 in command:
    alter table s_evt_act_x enable constraint S_EVT_ACT_X_P1
    Error report:
    SQL Error: ORA-02437: cannot validate (OSSTAGE.S_EVT_ACT_X_P1) - primary key violated
    02437. 00000 -  "cannot validate (%s.%s) - primary key violated"
    *Cause:    attempted to validate a primary key with duplicate values or null
               values.
    *Action:   remove the duplicates and null values before enabling a primary
               key.
    Can you please guide me with this issue .

    Please refer
    Script: Deleting Duplicate Rows from a Table (Doc ID 31413.1)
    How to Find or Delete Duplicate Rows in a Table (Doc ID 1004425.6)

  • Cannot find row from context to build the RowKey

    I have a table with 8 attributes!
    6 attributes are varchar2(20), so the input is just in textfields, the other 2 are booleans varchar2(1)!
    To select the boolean I made 2 comboboxes with the displayvalues Yes/No and datavalues Y/N!
    When I change 1 of the 6 attributes with the textfield, everything goes fine, but when I want to edit 1 of the 2 boolean attributes I get the following error:
    oracle.jbo.JboException: Cannot find row from context to build the RowKey
    The strangest thing is that all the settings from the attributes are the same and also the code in the dataeditcomponent.
    Does anyone knows what the error means and especially how to solve it!?
    If I change a boolean value the change is saved, but the error comes before you can see the changes!

    Hi Steve,
    thanks for your help.
    These are my steps to build the application:
    0.) JDev 904, WindowsXP, IE6.x, FireBird 0.7
    1.) New Project and Wizard 'New Business Components Package',
    only DeptImpl, default VO and default AppModule
    2.) New Project, Wizard 'Complete Struts-Based JSP Application'
    only default settings
    3.) Customize config of AppModule: Referenced Pool Size = 1
    4.) Start application, connect with two different browsers (IE and firebird)
    5.) Browse page DeptView1_Browse with both browsers
    1. Browser: Link Edit --&gt; edit&update attribute Loc of Dept 10 (no commit)
    2. Browser: Link Edit --&gt; edit (no update) attribute Loc of Dept 20
    6.) 2. Browser: update ==&gt; Error Message: Cannot find row from context to build the RowKey
    I have also tested JDev 9034/9033 with no error :-)
    I have build the same application in JDev 10g with ADF (no migration from other projects)
    and ran into another error message (same steps as above):
    JBO-29000: Unexpected exception caught: java.lang.reflect.InvocationTargetException, msg=null
    I don't know if my ADF-Struts project is assembled correctly but it works with just one session.
    My intention to set Referenced Pool Size = 1 was to test my code against some session releated bugs.
    I wanted to associate user information like name, role and PK with the SessionCookie instance (during login), via
    SessionCookie.setUserData(myInfos). The Information is used in VOs to get only the user related data
    and in EOs to store the real user name in an attribute like modifiedby/createdby
    (I use Tomcats as deployment platform):
    getApplicationModule().getSession().getUserData() -or-
    getDBTransaction().getSession().getUserData()
    Is there a better way to link own data to a 'session' on the level of business components?
    Can you reproduce my results?
    Ciao Markus

  • How to select all the colomns_names from a table, with their datatypes ..

    hi :)
    i would like to know, how to select in SQL all the columns names from a table with their datatypes so that i get something like this :
    Table 1 : table_name
    the column ID has the Datatype NUMBER
    the column name has the Datatype Varchar2
    Table 2 : table_name
    the column check has the Datatype NUMBER
    the column air has the Datatype Varchar2
    and that has to be for all the tables that i own ! ..
    P. S : i m trying to do this with java, so it s would be enough if you just tell me how to select all the tables_names with all their colums_names and with all their datatypes ! ..
    thank you :)
    i ve heard it can be done with USER_TABLES .. but i have no idea how :( ..
    Edited by: user8865125 on 17.05.2011 12:22

    Hi,
    The data dictionary view USER_TAB_COLUMNS has one row for every column in every table in your schema. The columns TABLE_NAME, COLUMN_NAME and DATA_TYPE have all the information you need.
    Another data dictionary view, USER_TABLES, may be useful, too. It has one row pre table.

  • 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

  • Deleting a row from parent table

    Dear Guru's
    I am having two table with parent - child relationship. My problem is when I am deleting a row from parent table the curresponding child row from child table also should be deleted.
    My Primary table 'Employee, EMPID Primary key
    Child table 'Privilage' inthis EMPID referencing the EMPID of Employee table
    My need is when I am deleting a row from parent table the curresponding child row from child table also should be deleted
    I issued the SQL query like,
    delete from employee where empid='12345' cascade constraints;
    Then it showing me error like,
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    Please resolve my issue , Its Top urgent
    Thanks & Cheers
    Antony

    Choosing How Foreign Keys Enforce Referential Integrity
    Oracle Database allows different types of referential integrity actions to be enforced, as specified with the definition of a FOREIGN KEY constraint:
    Prevent Delete or Update of Parent Key The default setting prevents the deletion or update of a parent key if there is a row in the child table that references the key. For example:
    CREATE TABLE Emp_tab ( 
    FOREIGN KEY (Deptno) REFERENCES Dept_tab);Delete Child Rows When Parent Key Deleted The ON DELETE CASCADE action allows parent key data that is referenced from the child table to be deleted, but not updated. When data in the parent key is deleted, all rows in the child table that depend on the deleted parent key values are also deleted. To specify this referential action, include the ON DELETE CASCADE option in the definition of the FOREIGN KEY constraint. For example:
    CREATE TABLE Emp_tab (
        FOREIGN KEY (Deptno) REFERENCES Dept_tab 
            ON DELETE CASCADE); Set Foreign Keys to Null When Parent Key Deleted The ON DELETE SET NULL action allows data that references the parent key to be deleted, but not updated. When referenced data in the parent key is deleted, all rows in the child table that depend on those parent key values have their foreign keys set to null. To specify this referential action, include the ON DELETE SET NULL option in the definition of the FOREIGN KEY constraint. For example:
    CREATE TABLE Emp_tab (
        FOREIGN KEY (Deptno) REFERENCES Dept_tab 
            ON DELETE SET NULL);
    SQL> conn scott/tiger
    Connected.
    SQL> create table ppk ( no number primary key);
    Table created.
    SQL> begin for inn in 1..10 loop insert into ppk values (inn); end loop; end;
    PL/SQL procedure successfully completed.
    SQL> create table ffk ( no number references ppk(no));
    Table created.
    SQL> begin for inn in 1..10 loop insert into ffk values (inn); end loop; end;
    PL/SQL procedure successfully completed.
    SQL> drop table ppk cascade constraints;
    Table dropped.Message was edited by:
    user52
    Message was edited by:
    user52
    Message was edited by:
    user52

  • Issue while deleting a row from a table

    Dear friends,
    i am getting an issue while deleting a row from a table, pls check screen shots , the first screen shot is my table contents
    when i delete 2 row , the second row is deleting properly like below screen shot
    but i want like below screen shot , Col1 contents should be like pic 1 . could any one pls let me know how to solve this issue.
    Thanks
    Vijaya

    Hi vijaya,
    please try this code, it will help you.
    DATA : it_rows  TYPE wdr_context_element_set,
              wa_rows LIKE LINE OF it_rows.
       DATA lo_nd_table TYPE REF TO if_wd_context_node.
        DATA lt_table TYPE wd_this->elements_table.
       DATA lo_el_table TYPE REF TO if_wd_context_element.
       DATA ls_vbap TYPE wd_this->element_table.
    DATA: ld_index TYPE i.
    data value TYPE sy-index.
    * navigate from <CONTEXT> to <table> via lead selection
       lo_nd_table= wd_context->get_child_node( name = wd_this->wdctx_table ).
    * @TODO handle non existant child
    * IF lo_nd_table IS INITIAL.
    * ENDIF.
    * get element via lead selection
    * alternative access  via index
    * lo_el_table = lo_nd_table->get_element( index = 1 ).
    * @TODO handle not set lead selection
       IF lo_el_table IS INITIAL.
       ENDIF.
    * navigate from <CONTEXT> to <table> via lead selection
       lo_nd_table = wd_context->get_child_node( name = wd_this->wdctx_table ).
    * @TODO handle non existant child
    * IF lo_nd_table IS INITIAL.
    * ENDIF.
       lo_nd_table->get_static_attributes_table( IMPORTING table = lt_table ).
    * @TODO handle non existant child
    * IF lo_nd_table IS INITIAL.
    * ENDIF.
    ** @TODO compute values
    ** e.g. call a model function
    * navigate from <CONTEXT> to <table> via lead selection
       lo_nd_table = wd_context->get_child_node( name = wd_this->wdctx_table ).
    * @TODO handle non existant child
    * IF lo_nd_table IS INITIAL.
    * ENDIF.
    ** @TODO compute values
    ** e.g. call a model function
    it_rows  =  lo_nd_table>get_selected_elements( ).
       CALL METHOD lo_nd_table->GET_LEAD_SELECTION_INDEX
       RECEIVING
         INDEX  = value .
      LOOP AT it_rows INTO wa_rows.
         CALL METHOD wa_rows->get_static_attributes
           IMPORTING
                  static_attributes = ls_table.
         READ TABLE lt_table INTO ls_table WITH KEY col1 = ls_table-col1.
          ld_index = value.
              ENDLOOP.
       CLEAR : ls_table-col2,
             ls_table-col2.
       MODIFY lt_table INDEX ld_index FROM ls_table.
      lo_nd_table->bind_table( new_items = lt_table set_initial_elements = abap_true ).

  • Cartesian of data from two tables with no matching columns

    Hello,
    I was wondering – what’s the best way to create a Cartesian of data from two tables with no matching columns in such a way, so that there will be only a single SQL query generated?
    I am thinking about something like:
    for $COUNTRY in ns0: COUNTRY ()
    for $PROD in ns1:PROD()
    return <Results>
         <COUNTRY> {fn:data($COUNTRY/COUNTRY_NAME)} </COUNTRY>
         <PROD> {fn:data($PROD/PROD_NAME)} </PROD>
    </Results>
    And the expected result is combination of all COUNTRY_NAMEs with all PROD_NAMEs.
    What I’ve noticed when checking query plan is that DSP will execute two queries to have the results – one for COUNTRY_NAME and another one for PROD_NAME. Which in general results in not the best performance ;-)
    What I’ve noticed also is that when I add something like:
    where COUNTRY_NAME != PROD_NAME
    everything is ok and there is only one query created (it's red in the Query plan, but still it's ok from my pov). Still it looks to me more like a workaround, not a real best approach. I may be wrong though...
    So the question is – what’s the suggested approach for such queries?
    Thanks,
    Leszek
    Edited by xnts at 11/19/2007 10:54 AM

    Which in general results in not the best performanceI disagree. Only for two tables with very few rows, would a single sql statement give better performance.
    Suppose there are 10,000 rows in each table - the cross-product will result in 100 million rows. Sounds like a bad idea. For this reason, DSP will not push a cross-product to a database. It will get the rows from each table in separate sql statements (retrieving only 20,000 rows) and then produce the cross-product itself.
    If you want to execute sql with cross-products, you can create a sql-statement based dataservice. I recommend against doing so.

  • How to list all the rows from the table VBAK

    Friends ,
    How to list all the rows from the table VBAK.select query and the output list is appreciated.

    Hi,
    IF you want to select all the rows for VBAK-
    Write-
    Data:itab type table of VBAK,
           wa like line of itab.
    SELECT * FROM VBAK into table itab.
    Itab is the internal table with type VBAK.
    Loop at itab into wa.
    Write: wa-field1,
    endloop.

  • Unload 10,000,000 of rows from a table.

    Hi Group,
    Is there any optimized, quick way to unload 10 million of rows from a table to a text file on the server, each field has to be separated with "|" symbol.
    Thanks a lot
    Oracle version 10.2.0.4
    Platform: Linux RH 64 bits

    sb92075 wrote:
    SET COLSEP='|'
    spool unload.csv
    SELECT ........
    spool offExactly -- no fancy tools are needed for this, just SQL*Plus. You might need a few more SET commands to make sure that the file is clean, with no extraneous headers, footers, trailing white space etc.. Just experiemnt with a set of something like 200 rows of the table.

  • 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

  • Count rows from several tables

    hello,
    im trying to count row from multiple tables
    for example i need the select statement to produce the following
    table_name count
    table1 5
    table2 6
    table3 3
    i came up with the following script but it counts the number of tables i have
    select object_name, (select count(*) from user_tables where table_name = object_name) from all_objects
    where object_type = 'TABLE'

    Manik wrote:
    May be possible:
    Check this:
    SELECT table_name,
    TO_NUMBER (
    EXTRACTVALUE (
    xmltype (
    DBMS_XMLGEN.getxml ('select count(*) c from ' || table_name)),
    '/ROWSET/ROW/C'))
    COUNT
    FROM (select * from all_tables where table_name in ('TABLE1','TABLE2'))
    WHERE owner = 'SCOTT';Cheers,
    Manik.Awesome Manik... Just too good. Thanks.
    I wish i could have given you the 'Correct' points. ;-)
    Can you please explain the logic in brief? Will be helpful for everybody to understand...

Maybe you are looking for

  • Can I do this: Use wireless network as WAN and create my own LAN.

    I travel quite a bit and many hotels now do not have wired in-room networks. So I'm looking for a way to use the wireless network as a wide area network and create a local network in-room behind a router/firewall, preferably with a private SSID.. I'v

  • [SOLVED] Error mounting an ISO file located in an EncFS folder

    I have some multimedia files inside an EncFS folder (decrypted via cryptkeeper). When trying to loop mount the ISO files I get: mount: foo.iso: failed to setup loop device: Permission denied There's no error mounting the same ISO from a «regular» FS.

  • Discount after Excise And Before VAT

    Dear All, We have the below requirement, Vendor is giving the discount After Taxes & before calculating the VAT. How to meet this requirement ? Right now i have created a condn type & added in tax procedure, But not able to meet the requirement. We a

  • Flash Player 9.0.124 MSI Problems

    I've downloaded the 9.0.124 version of Adobe Flash Player (both Active_X & Plugin versions), but am not able to put them into a Group Policy Object. When I try to include them in the GPO, I receive the message "Add operation failed. Unable to extract

  • How can I distinguish between the first and the rest in Smartforms??

    I have made an Invoice in Smartform. I have to take three copies of that. In the first copy it will be printed "ORGINAL INVOICE" and in the next copies it will print "Duplicate copy".  How can I distinguish between the first and the rest in Smartform