Best way to obtain records that are NOT in another table

I have two rather large tables in oracle. An Account table that has millions of rows. Each account may be enrolled into a particular program and therefore can also be in an Enrollment table, also with millions of rows. I'm trying to find the most optimal way to find any accounts in ACCOUNT that are NOT in the Enrollment table.
I was doing something like this:
select /*+ index(ACCOUNT idx_acct_no) */
a.acct_no
from ACCOUNT a
where a.acct_no not in (Select e.acct_no from ENROLLMENT e);
This takes a VERY long time to execute, even though I am using the index.
I even tried to use the PK on the ACCOUNT table, as it is also a FK on the ENROLLMENT table as such:
select a.acct_no
from ACCOUNT a
where a.id not in (Select e.id from ENROLLMENT e);
this too takes too long to get back (if at all).
Is there a better way to do this selection please?

Well if you have the energy to type in the whole list, the syntax you've given will work, unless you blow the permitted number of elements.
But a practical solution would be to turn the list into a table. You still haven't got the hang of this "giving us enough information" concept, so let's presume:
(1) you're on a version of the databasse whoch is 9i or higher
(2) you have this list in a file of some sort.
In which case use an external table or perhaps a pipelined function to generate output which can be used in a SQL statement.
If neither of these solutions works for you please provide sufficient information for us to answer your question correctly. Your future co-operation is appreciated.
cheers, APC

Similar Messages

  • Best approach to delete records that are not in the source table anymore.

    I have a situation where I need to remove records from dimensions that are not in the source data anymore. Right now we are not maintaing history, i.e. not using SCD but planning for the next release. If we did that it would be easy to figure the latest records. The load is nightly and records are updated and new added.
    The approach that I am considering is to join the dimension tables the the sources on keys and delete what doesn't join. However, is there perhaps some function in OWB that would allow to do this automatically on import so it can be also in place for the future?
    Thanks!

    Bear in mind that deleting dimension records becomes problematic if you have facts attached to them. Just because this record is no longer in the active set doesn't mean that it wasn't used historically, and so have foreign key constraints on it in your database. IF this is the case, a short-term solution would be to add an expiry_date field to the dimension and update the load to set this value when the record disappears rather than to delete it.
    And to do that, use the target dimension as a source table, outer join it to the actual source table on the natural key, and so your update will set expiry_date=nvl(expiry_date,sysdate) to set to sysdate if this record has not already been expired on all records where the outer join fails.
    Further consideration: what do you do if the record is re-inserted into the source table? create a new dimension key? Or remove the expiry date?
    But I will say that I am not a fan of deleting records in most circumstances. What do you do if you discover a calculation error and need to fix that and republish historical cubes? Without the historical data, you lose the ability to do things like that.

  • Omit notes during MIDI recording that are not in defined scale

    I'm looking for a way to do the following in Logic, but am not sure how to set this up. I want to be able to:
    1. Create a new midi track
    2. In selected midi track, select a scale (for example, Pentatonic Minor)
    3. Press record
    4. During recording, only notes played from Pentatonic Minor scale would "register" (make a sound) and be recorded. All other notes pressed on midi controller that are not in Pentatonic Minor would not "register" nor be recorded in the sequencer.
    Additionally helpful would be that in the piano roll sequencer after recording, I could only drag notes up or down along the Pentatonic Minor scale. In other words, I would not be allowed to drag a recorded note to another note that is not in Pentatonic Minor. If a note was dragged onto a "disabled" note, it would automatically snap to its nearest neighbor note in the Pentatonic Minor scale. Additionally useful would be to have all disabled notes (notes that are not in the Pentatonic Minor scale) appear to be disabled (grayed out) in the piano roll sequencer.
    If this is not possible, is there any feature in Logic that will get me close to doing what I want? If not, is there any other sequencer that does this? I know this is something I could probably do in Max, but I was hoping to be able to do it in Logic. Thanks.

    Patch this between the PhysicalIn and the SequencerIn in the Environment:
    !http://home.arcor.de/fuzzfilth/Other/mod.png!
    Get it here:
    http://home.arcor.de/fuzzfilth/Other/Modulator.zip
    Christian

  • How to create an XSD for file adaptor which will ignore the records that are not required.

    Hi All,
       I have a requirement, the Fixed Length file contains
    30013742387462382938742      82347023984623087   
    30037348237  983743  9837423098  98347 
    10108472398   98034702398409238 9838472398   09823409238
    300163527 387462398746 38746293874693746324763
    101037642873643 37438724683746837648 873648736
    200138743986493874398
    2002738469837246
    10003784629837469283746937463987469387
    I need to select only the records that startswith 3001 and 3003 which are of different types and ignore the remaining records like 1010,2001,2002,1000.
    Can any one help me on this.

    You can make use of "conditionValue" or "startsWith" attributes while designing you native XSD.
    Check this example - Native Format Builder Wizard - 11g Release 1 (11.1.1.6.3) for better understanding.

  • How to calculate Sum of records that are not Suppressed

    Hi All Experts,
    I have Created A layout for SAP B1 in crystal report.Because of Some Condition I have  to Suppress Detail Section.
    The Suppress Condition is As Follows
    {ExcisePur.ItemCode}=Previous({ExcisePur.ItemCode}) And {ExcisePur.Batchnum}=Previous({ExcisePur.Batchnum})
    And it is Working Fine,the Desired Detail Section is Suppressed.
    Now I Have to take Sum of Records ,But that records are also Calculated which are Suppressed.
    For these I have Read Several post where someone had same problem,
    there they have Asked to Create A Running Total And use the Formula in evaluate section same as in Suppress Condition but opposite of it.
    I did the same thing using these Formula
    {ExcisePur.ItemCode}<>Previous({ExcisePur.ItemCode}) And {ExcisePur.Batchnum}<>Previous({ExcisePur.Batchnum})
    But it is Calculating only the Suppressed Record But Not the Record which is to be Calculated.
    Please help me to Accomplish this.
    I am very Much blank where I am  going wrong.
    Regards,
    Gayatri Shukla

    Hi Gayatri,
    I'm not too sure why this isn't working as the logic seems correct.
    Here's another way to do this:
    1) Create another formula and place this on the Details Section:
    whileprintingrecords;
    numbervar x;
    if onfirstrecord then
    x := {Field_to_summarize}
    else if {ExcisePur.ItemCode} <> Previous({ExcisePur.ItemCode}) And {ExcisePur.Batchnum} <> Previous({ExcisePur.Batchnum}) then
    x := x + {Field_to_summarize};
    2) Create another formula and place this on the Report Footer:
    whileprintingrecords;
    numbervar x;
    -Abhilash

  • Obtain count of values, including the values that are not in the table

    I have values: 1,2,3,7,8,9
    and my table contain value 3,7,8,3
    I need get result of select
    -value- -count-
    -1-     -0-
    -2-     -0-
    -3-     -2-
    -7-     -1-
    -8-     -1-
    -9-     -0-
    I tried
    select value, count(value) from table where value in ('1','2','3','7','8','9') group by value
    but I get only
    -value- -count-
    -3-     -2-
    -7-     -1-
    -8-     -1-
    Thank you for help

    Thank you for help but this is not functional if values are text (varchar).Have you mentioned that ? In your example post you have mentioned only numeric values. Why don't you try yourself, When you have an working (? Oops, there is no version mentioned by OP, So may not be working) example ?
    SQL> SELECT * FROM v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    SQL> SELECT job,COUNT(job)
      2  FROM emp
      3  GROUP BY job;
    JOB       COUNT(JOB)
    CLERK              4
    SALESMAN           4
    PRESIDENT          1
    MANAGER            3
    ANALYST            2
    SQL> SELECT column_value,COUNT(job)
      2  FROM emp e, TABLE(sys.odciVARCHAR2list('CLERK','PROGRAMMER','SALESMAN'
      3                                        ,'SALESMAN','DBA','PRESIDENT','MANAGER'
      4                                        ,'Architect','ANALYST')) t
      5  WHERE e.job(+)=t.column_value
      6  GROUP BY column_value
      7  ORDER BY 1;
    COLUMN_VALUE
    COUNT(JOB)
    ANALYST
             2
    Architect
             0
    CLERK
             4
    COLUMN_VALUE
    COUNT(JOB)
    DBA
             0
    MANAGER
             3
    PRESIDENT
             1
    COLUMN_VALUE
    COUNT(JOB)
    PROGRAMMER
             0
    SALESMAN
             8

  • Best way to import photos that are already in the book.

    Hi,
    I have a huge book with a lot of photos. When I drag the text in, the photos come in also, but they are all moved around. Is there any way to import the text in and have the photos not move around and stay where they're supposed to be?
    Thanks,
    Elaine

    Expect to need to rework once the content is in iBA.
    See Optimizing performance in your iBooks Author books for tips.

  • Is there any way to request songs that are not in itunes store?

    I would really like to purchase the song "Puttin' it Down" by Beck, but it is not on iTunes store!

    try here: iTunes Store Requests

  • How do I handle values in source that are not in "lookup" table?

    hi there,
    I have 3 tables (all Oracle technology):
    1) Source table: CALLS with columns MSISDN, TRANS_DATE, TYPE, COST, DURATION
    2) Lookup table: SUBSCRIBERS with columns SUBSCRIBERID, MSISDN, IMSI
    3) Target table: FACT_CALLS with columns SUBSCRIBERID (not null), CALLDATE, CALLTYPE, CALLDURATION, CALLCHARGE.
    Join between source and lookup table:
    NVL(CALLS.MSISDN,0) =SUBSCRIBERS.MSISDN)
    Mappings on target:
    FACT_CALLS.SUBSCRIBERID --> SUBSCRIBERS.SUBSCRIBERID
    FACT_CALLS.CALLDATE --> CALLS.TRANS_DATE
    FACT_CALLS.CALLTYPE --> CALLS.TYPE
    FACT_CALLS.CALLDURATION --> CALLS.DURATION
    FACT_CALLS.CALLCHARGE --> CALLS.CHARGE
    I have a dummy value in SUBSCRIBERS with values MSISDN = 0, SUBSCRIBERID = 0 and IMSI = 0, to be used if MSISDN in the source table is null or does not exist in the lookup table.
    The NVL on the join takes care of the case when source MSISDN is null and this is working fine i.e. returns 0 for SUBSCRIBERID.
    The problem occurs when the source MSISDN does have a value but such a value does not exist in the lookup table, such records are rejected.
    How do I implement a solution for this?

    hi Guru,
    Yes I have 2 source tables and a target.
    1) I created a join by dragging MSISDN on CALLS to MSISDN on SUBSCRIBERS then added the NVL part to have NVL(CALLS.MSISDN,0) =SUBSCRIBERS.MSISDN)
    2) the target does not have MSISDN. Using the join the target SUBSCRIBERID column gets populated with the correct value from the lookup table.
    i.e. FACT_CALLS.SUBSCRIBERID = (select SUBSCRIBERID from SUBSCRIBERS where SUBSCRIBERS.MSISDN = CALLS.MSISDN)

  • Query to Identify Data in One Table Not In Another Table

    I need to create a query that will return the records in one table that are not in another table.  Here is the structure of my data tables:
    tbl_Practice – contains information about management practices.  The primary key field is “ID” which is an autonumber field.
    tbl_Controls – contains information about internal controls associated with the management practices.  The primary key is “ID” which is an autonumber.
    tbl_PracticeJoin – this is a table that contains the mapping of controls to practices.  Some practices can have multiple controls assigned to them and some controls can be mapped to multiple practices. 
    This table’s primary key is “ID” which is an autonumber field.  The only other data included in this table are the primary keys of the practice and control.  Those field names are “PracticeIDFK” and “ControlIDFK”.
    In this application, the user will normally enter practices and controls at the same time; however, there may be instances where a control is entered and it is not known at that time what practice(s) it should
    be mapped to.  I want to be able to run a query that will show me any controls that are in the tbl_Controls which are not in tbl_PracticeJoin.  I would like to be able to do the same with the practice table. 
    Thanks.

    The easiest way to do this is through the 'Find Unmatched Query Wizard'.
    On the Create tab of the ribbon, click Query Wizard.
    Select 'Find Unmatched Query Wizard'.
    Click OK.
    Select tbl_Controls, then click Next >.
    Select tbl_PracticeJoin, then click Next >.
    Select ID in tbl_Controls and ControlIDFK in tbl_PracticeJoin (if the wizard hasn't already done so automatically), then click Next >.
    Add the fields from tbl_Controls that you want to see to the list on the right; click >> if you want to add them all at once. Then click Next >.
    Access proposes a name for the query; you can edit the name if you wish.
    Click Finish.
    You can do the same for tbl_Practice and tbl_PracticeJoin, with PracticeIDFK instead of ControlIDFK.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • Download  resources that are not listed in the JNLP file

    There is some way to download resources that are not listed in the JNLP file, and then
    ask for them with DownloadService ? (isResourceCached)
    thanks.

    currently, the jnlp spec requires DownloadService to access only resources specified in the jnlp file..
    changing this is a proposed RFE for the next spec version:
    4908304: JWS DownloadService should not require mention in JNLP file
    /Dietz

  • Determining indexes that are not used in 10g

    Is there a way to identify indexes that are not utilized in 10g? We have ADDM and AWR running nightly.
    Thanks in advance...

    You can enable index monitoring with
    alter index <index_name> monitoring usage;
    When the index is used V$OBJECT_USAGE.USED column will be set to YES. If the index is not used the USED column will show NO.
    test@ORCL> alter index i_test monitoring usage;
    Index altered.
    Elapsed: 00:00:00.04
    test@ORCL> select * from v$object_usage;
    INDEX_NAME                     TABLE_NAME                     MON USE START_MONITORING    END_MONITORING
    I_TEST                         TEST                           YES NO  01/04/2007 07:52:21
    Elapsed: 00:00:00.04
    test@ORCL> explain plan for
      2  select object_id from test;
    Explained.
    Elapsed: 00:00:00.10
    test@ORCL> select * from v$object_usage;
    INDEX_NAME                     TABLE_NAME                     MON USE START_MONITORING    END_MONITORING
    I_TEST                         TEST                           YES NO  01/04/2007 07:52:21
    Elapsed: 00:00:00.00
    test@ORCL> select count(*) from test;
      COUNT(*)
         50425
    Elapsed: 00:00:00.00
    test@ORCL> select * from v$object_usage;
    INDEX_NAME                     TABLE_NAME                     MON USE START_MONITORING    END_MONITORING
    I_TEST                         TEST                           YES NO  01/04/2007 07:52:21
    Elapsed: 00:00:00.00
    test@ORCL> select * from test where object_id =1;
    no rows selected
    Elapsed: 00:00:00.07
    test@ORCL> select * from v$object_usage;
    INDEX_NAME                     TABLE_NAME                     MON USE START_MONITORING    END_MONITORING
    I_TEST                         TEST                           YES YES 01/04/2007 07:52:21
    Elapsed: 00:00:00.00
    test@ORCL>You turn of index monitoring with the following:
    alter index <index_name> nomonitoring usage;

  • Records in a table that are not older than two weeks

    Hey everyone,
    I have a mysql table which has a column DATE which contains the date the enty was inserted
    I need to write a script which keeps only those records that are no older than two weeks.
    Can this be done in sql?
    I can do it in Java but I guess this is not the most efficient way.
    I use jsp and servlets in my app.

    I just tried out the above code:
    DELETE FROM myTableHere  WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) <= DATE;This is the error that I got:
    mysql> DELETE FROM myTableHere WHERE DATE_SUB(CURDATE(),INTERVAL 14 DAY) <= DATE;
    ERROR 1054 (42S22): Unknown column 'DATE' in 'where clause'
    mysql>
    my sql table has the currentDate column which specifies the current date and time when this entry was inserted into the DB. To get current date and time I use 'now()' function of sql.
    what is the problem?
    Thanks.

  • Is there a way to create a project with custom audio settings that are NOT only "Stereo" or "Surround"?

    Is there a way to create a project with custom audio settings that are NOT only "Stereo" or "Surround"?
    Thanks!
    -Adrian

    the old apps are on my computer but they have had upgrades since they were put on the ipod originally.  you think you would get a warning about this when you restored. I was not worried about losing the progress of the apps but i would have been worried about the app it self!!!!!

  • Is there a way for my images that are links NOT to be denoted by whatever color i set my links to be in my page properties?

    Hi there.
    i have set my links to be black in my page properties.  i have somes images that i am using for links and i do not want the to have a black box tracing their outline.  it's messing up my design and tables.  is there a way for my images that are links NOT to be denoted by whatever color i set my links to be in my page properties?
    see attachment.
    thanks for sharing your knowledge with me.
    gina

    If you would like your NON-linked images to have a border, and only remove the border from linked images then this css:
    a img { border:none; }
    E. Michael Brandt
    www.divahtml.com
    www.divahtml.com/products/scripts_dreamweaver_extensions.php
    Standards-compliant scripts and Dreamweaver Extensions
    www.valleywebdesigns.com/vwd_Vdw.asp
    JustSo PictureWindow
    JustSo PhotoAlbum, et alia

Maybe you are looking for