Count Records in Table Except If Related Record Exists in Child Table

Dear All
I have the following query that counts all of the records in the table SENAlert based upon the teacher's username in a related table.
SELECT COUNT(SENAlert.SENAlertID) AS Expr1
FROM Class INNER JOIN ClassMember ON Class.ClassClassCode = ClassMember.ClassMemberClassCode
INNER JOIN Student ON ClassMember.ClassMemberStudentID = Student.StudentID
INNER JOIN SENAlert ON Student.StudentID = SENAlert.SENAlertStudentID
INNER JOIN Teacher ON Class.ClassTeacherCode = Teacher.TeacherCode
WHERE (Teacher.TeacherUsername = 'dsmith')
I need to extend this query by adding another table called SENAlertHistory. I would like to count the number of alerts (SENAlertID) for the specified teacher
but where there is no related record in the SENAlertHistory table. Here's what the relationship diagram looks like:
What's going to happen is when a teacher clicks a button to say they have read an alert, I will record this in the SENAlertHistory table. Therefore when performing a count of how many unread alerts the teacher has, I need to ignore the alerts they have
already read (i.e. the records in the SENAlertHistory table).
This is a bit too advanced for me -- I have tried! I was hoping someone would be able to help me please?
Many thanks
Daniel

Try below code
-- If you dont need the read alert count
SELECT COUNT(SENAlert.SENAlertID) AS Expr1
FROM Class INNER JOIN ClassMember ON Class.ClassClassCode = ClassMember.ClassMemberClassCode
INNER JOIN Student ON ClassMember.ClassMemberStudentID = Student.StudentID
INNER JOIN SENAlert ON Student.StudentID = SENAlert.SENAlertStudentID
INNER JOIN Teacher ON Class.ClassTeacherCode = Teacher.TeacherCode
WHERE (Teacher.TeacherUsername = 'dsmith')
AND NOT EXISTS
(SELECT * FROM SenAlertHistory SAH WHERE Teacher.TeacherCode = SAH.SenAlertHistoryTeacherCode and SENAlert.SENAlertID = SAH.SEMAlertHistorySENAlertID )
-- If you need the read alert count
SELECT COUNT(SENAlert.SENAlertID) - COUNT(SAH.SEMAlertHistorySENAlertID) AS Expr1,COUNT(SAH.SEMAlertHistorySENAlertID)readalert
FROM Class INNER JOIN ClassMember ON Class.ClassClassCode = ClassMember.ClassMemberClassCode
INNER JOIN Student ON ClassMember.ClassMemberStudentID = Student.StudentID
INNER JOIN SENAlert ON Student.StudentID = SENAlert.SENAlertStudentID
INNER JOIN Teacher ON Class.ClassTeacherCode = Teacher.TeacherCode
LEFT OUTER JOIN SenAlertHistory SAH ON Teacher.TeacherCode = SAH.SenAlertHistoryTeacherCode and SENAlert.SENAlertID = SAH.SEMAlertHistorySENAlertID
WHERE (Teacher.TeacherUsername = 'dsmith')
Thanks
Saravana Kumar C

Similar Messages

  • Selection in the master table is not getting reflected in the child table

    <p> I have a 4 level master detail relationship.I have a bounded taskflow where I have a master in the first view.The child (The other two levels as a tree) in the second view.I move to second view when i click the command link(Each row has a command link) of the master table (present in the first view).</p>
    <p>At the very first time when i try to insert a row in the child it's successful .I am able to see the same in the second view (The corresponding child of the master row which i have clicked).The 2 view is not refreshed i have panel strech layout in the 2 view which i am refreshing(PPR) on inserting the row. The master table is not refreshed as it is in the 1 view.I am not manipulating the master table but it was being set to the first row the second time .Added to that the 2 view doesn't have parent table .
    </p>
    Thanks,
    Raj.

    Hi Frank,
    I am using jdev 11.1.1.6 and integrated wls.
    I have a single taskflow.I have a 4 level master detail.The vo's are connected through a view link . I have dropped the first level as a table . On selecting a row the corresponding children are displayed.The children are displayed as a tree. I have a tree context menu where i have inserted a row using popup . When the user clicks on the ok dialog i am commiting the data and refreshing the tree.
    Now the problem is when i first create the row it's working properly . After when i try to create another row this time the currency of the first level is reset to the first row.
    As suggested by you i have tried disabling the commit opertion . But the issue still occurs.
    Thanks,
    Raj
    Edited by: RajaSekharReddy.M on Feb 26, 2013 6:03 PM

  • ORA-01092: ORACLE instance terminated. Disconnection forced ORA-00942: table or view does not exist on 12C RAC

    Hi Geeks,
    I have encountered an issue while starting up my database on 12c RAC.
    Till mount it goes fine but when i attempt to open it throws me an error.
    Total System Global Area 1.5400E+10 bytes
    Fixed Size                  4737560 bytes
    Variable Size            2952791528 bytes
    Database Buffers         1.2415E+10 bytes
    Redo Buffers               26857472 bytes
    Database mounted.
    SQL> alter database open;
    alter database open
    ERROR at line 1:
    ORA-01092: ORACLE instance terminated. Disconnection forced
    ORA-00942: table or view does not exist
    Process ID: 11338068
    Session ID: 1429 Serial number: 3
    Here is the trace file output...
    ORACLE_HOME = /oracle_home/app/orahome
    System name:    AIX
    Node name:      INS1
    Release:        1
    Version:        7
    Machine:        00C8CCA74C00
    Instance name: INST1
    Redo thread mounted by this instance: 1
    Oracle process number: 7
    Unix process pid: 20381876, image: oracle@ins1 (TNS V1-V3)
    *** 2014-11-27 22:49:20.892
    *** SESSION ID:(197.5) 2014-11-27 22:49:20.892
    *** CLIENT ID:() 2014-11-27 22:49:20.892
    *** SERVICE NAME:() 2014-11-27 22:49:20.892
    *** MODULE NAME:(sqlplus@ins1 (TNS V1-V3)) 2014-11-27 22:49:20.892
    *** ACTION NAME:() 2014-11-27 22:49:20.892
    2014-11-27 22:49:20.889716 : Start recovery for domain=0, valid=0, flags=0x4
    *** 2014-11-27 22:49:24.580
    Successfully allocated 32 recovery slaves
    Using 3 overflow buffers per recovery slave
    *** 2014-11-27 22:49:24.740
    Thread 1 checkpoint: logseq 15, block 2, scn 3510749
      cache-low rba: logseq 15, block 3
        on-disk rba: logseq 15, block 72, scn 3510824
      start recovery at logseq 15, block 3, scn 0
    *** 2014-11-27 22:49:24.981
    Started resilvering redo thread 1 seq 15 blocks 72-73
    *** 2014-11-27 22:49:24.994
    Completed resilvering redo thread 1 seq 15
    *** 2014-11-27 22:49:24.994
    Started writing zeroblks thread 1 seq 15 blocks 74-81
    *** 2014-11-27 22:49:24.994
    Completed writing zeroblks thread 1 seq 15
    ==== Redo read statistics for thread 1 ====
    Total physical reads (from disk and memory): 4096Kb
    -- Redo read_disk statistics --
    Read rate (ASYNC): 35Kb in 0.25s => 0.14 Mb/sec
    Longest record: 0Kb, moves: 0/104 (0%)
    Longest LWN: 2Kb, moves: 0/33 (0%), moved: 0Mb
    Last redo scn: 0x0000.0035922b (3510827)
    ----- Recovery Hash Table Statistics ---------
    Hash table buckets = 262144
    Longest hash chain = 1
    Average hash chain = 25/25 = 1.0
    Max compares per lookup = 1
    Avg compares per lookup = 151/176 = 0.9
    *** 2014-11-27 22:49:25.007
    KCRA: start recovery claims for 25 data blocks
    *** 2014-11-27 22:49:25.039
    KCRA: blocks processed = 25/25, claimed = 25, eliminated = 0
    *** 2014-11-27 22:49:25.054
    Recovery of Online Redo Log: Thread 1 Group 6 Seq 15 Reading mem 0
    *** 2014-11-27 22:49:25.060
    Completed redo application of 0.02MB
    *** 2014-11-27 22:49:25.235
    Completed recovery checkpoint
    ----- Recovery Hash Table Statistics ---------
    Hash table buckets = 262144
    Longest hash chain = 1
    Average hash chain = 25/25 = 1.0
    Max compares per lookup = 1
    Avg compares per lookup = 176/176 = 1.0
    Recovery sets nab of thread 1 seq 15 to 74 with 8 zeroblks
    *** 2014-11-27 22:49:26.000
    2014-11-27 22:49:26.000433 : Validate domain 0
    2014-11-27 22:49:26.001348 : Validated domain 0, flags = 0x0
    *** 2014-11-27 22:49:28.315
    Count of ofsmtab$: 0 entries
    *** 2014-11-27 22:49:28.732
    ORA-00942: table or view does not exist
    ORA-00942: table or view does not exist
    *** 2014-11-27 22:49:28.738
    USER (ospid: 20381876): terminating the instance due to error 942

    In my case the issue has fixed by executing the following..
    grant SELECT on SYS.USER$ to XDB;
    grant SELECT on SYS.USER$ to CTXSYS;
    grant SELECT on SYS.USER$ to DVSYS;
    grant SELECT on SYS.USER$ to LBACSYS;
    grant SELECT on SYS.USER$ to APEX_040200;
    grant SELECT on SYS.USER$ to DV_SECANALYST; 
    Refer the above screen shot...

  • Insert data Flatfile table to Parent and child tables

    Hi All,
        I have Flatfile table which is we getting from daily txt files and i want to populate flatfile data to parent as well as child tables. parent table has primary key as ID. This ID is foreign key of child tables. 
    Here i have mentioned our process.
    1. Flatfile duplicates has to remove with condition of daily date.
    2. Before Insert parent table have to check duplicate(we have Unique key of 4 columns in parent) if duplicate is there we have to delete duplicate then Insert into parent table unique records(Primary key is ID).(here why we are delete duplicate record meaning
    we getting daily files so if any records updated in future that record should be insert to parent and child table so only we delete old records and insert new records).
    3.After insert parent we have to populate child tables from Flatfile table as well as we have to insert parent table primary key as foreign key of child tables.
    4. if any truncation error occurs that errors should go to error log table.
    Right now we are using cursor for this concept and cursor has performance issue. so we are trying to optimize other way to populate parent and child table to increase performance to populate.
    Please help us to which way to do this process increase of performance .
    Please  can any one reply.

    Hi RajVasu,
    Since this issue is related to Transact-SQL, I will move this thread to Transact-SQL forum. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 
    Thank you for your understanding and support.
    Regards,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Child Table

    i have made 2 child tables of one parent table in form... 1 child table is made by default through foreign key.. and one i made manually.. everything is working fine except one problem... when i go to create new record in second child table so previously inserted records come overthere whereas previos data should be cleared while new record inserting... how can i handle this issue.. plz help..
    kamran

    Hi,
    Is there anything on the second table that can be used as a filter that would be available from the main table? Without such a filter, it would be difficult to keep the second table clear for new records on screen.
    Andy

  • Child Table Cache Problem - Only in Environment

    Hi All,
    I have master-child tables in a page. Master table is based on a VO and child table is based on pl/sql EO. When user updates any child table row and hits on save, I load the same page again by releasing AM. The problem is when the page loads again after update, two records are being shown in child table. One record with old value and other record with the modified value. But in database only record exists and it is successfully updated. If we again hit "Apply" on the page then only the updated record is shown. I am sure this is due to vo/eo caches. But after insert/update, I am forwarding to same page with retain am set to false. So this should clear-off all associated caches. I had even tried to clear vo caches explicitly before redirection. But even this doesnt help. This issue exists only in the environment but cannot be reproduced locally in JDev. Its working perfectly fine in JDev.
    Any pointer on the above issue?
    Thanks in advance,
    Murari

    hmm...caching may be happening at webbean level rather than the VO level. You can confirm this by getting the value of VO.getrowcount in processRequest.
    For both Classical table as well as Advanced Table, clearcache() method is available to clear the cache of data object for inner table. Call this in processRequest. You can put in a check to call this only when you self-redirect to this page.

  • How to update parent and child tables while updating parent table

    I have a parent table EMPLOYEE which includes columns (sysid, serviceno,employeename...) sysid is Primary key, serviceno is Unique key and I have child table DEPENDENT includes columns (sysid,employee_sysid,name,dob...) here again SYSID is primary key for DEPENDENTS table, employee_sysid is Foreign key of EMPLOYEE table.
    Now I want to change SYSID (using sequence) in EMPLOYEE table which need to be update in DEPENDENTS table as well
    Note: I have 10000 records in EMPLOYEE table as well as I have 5 more child tables which need to update new SYSID.
    please help me

    first disable the FOREIGN KEY Constraints.
    you can update Parent as well as Child record also with help of trigger.
    here i am giving you one examlpe..it may help u.
    create table parent(id number primary key,name varchar2(100))
    create table child_1(id number primary key,p_id number,dob date,
    CONSTRAINT FK_id FOREIGN KEY (p_id) REFERENCES parent (ID))
    create table child_2(id number primary key,p_id2 number,addr varchar2(1000),
    CONSTRAINT FK_id2 FOREIGN KEY (p_id2) REFERENCES parent (ID))
    insert some test data to parent and child tables.
    alter table child_2 disable constraint FK_id2
    alter table child_1 disable constraint FK_id2
    CREATE OR REPLACE TRIGGER delete_child
    BEFORE UPDATE ON parent
    FOR EACH ROW
    BEGIN
    UPDATE CHILD_1
    SET P_ID=:NEW.ID
    WHERE P_ID=:OLD.ID;
    UPDATE CHILD_2
    SET P_ID2 =:NEW.ID
    WHERE P_ID2=:OLD.ID;
    END;
    then Upadte parent table primary key col and check the child tables.
    then enable the constraints...

  • Parent values should be enter into child table in 11g adf

    HI ALL,
    i' m using oracle 9i with 11g adf jdeveloper.
    I have one parent table and child table respectively . I'm display both the parent and child table in one jsf page.Some fields/records in child table have same as in parent table.so when we enter values in parent fields the child table value should be placed.
    Ex:
    PARENT TABLE
    ID
    NAME
    LOC
    SAL
    DEPART
    COMP
    CHILD TABLE
    CID
    PID
    CNAME
    LOC
    SAL
    DEPART
    CNO
    CPNR
    LOC,SAL and DEPART are common fields in both tables
    I display all the feilds in parent table , but i won't display LOC,SAL and DEPART field from Child table . Now i when i fill value in fields and fire submit . the values of LOC,SAL and DEPART parent table values should be enter in child table fields
    Thanks in advance.

    Create a custom Application Module method and expose it to the AM client interface. In it set the child VO attributes from the parent VO and submit. Bind this custom method to your Submit in the ViewController and call it from a backing bean.
    Regards,
    Nick

  • OIM child tables

    Hi Guys
    A quick question about OIM child tables. I need to send the child table data in a mail whenever a record is inserted or deleted in the child table. This is same as sending notification on addition or removal of an target resource role.
    I want to know that how I can access the child table record that has been deleted (using OIM API).
    When a record is added, I am able to get the information from the table data as a new records was updated in the table.

    The easiest way would be to just have a task that is kicked off as a result of the add or remove in the child form task.
    This thread may be helpful: Re: AD group consolidated notification.
    Best regards
    /Martin

  • On insert into parent table insert into child tables

    hi all,
    please suggest me an idea for below scenario in plsql
    i have a main table where every day 10k records are inserted,
    now when ever the main table gets inserted the same records should inserted into two other child tables.
    main table will have 20 columns and two child tables will have 10 each columns with one common column in all three tables.
    suggest me if a trigger is best or a procedure is best for this if possible with a solution.
    thanks in advance

    look at INSERT ALL
    sample from http://psoug.org/reference/insert.html
    INSERT ALL
      INTO ap_cust VALUES (customer_id, program_id, delivered_date)
      INTO ap_orders VALUES (order_date, program_id)
      SELECT program_id, delivered_date, customer_id, order_date
        FROM airplanes;

  • Selecting Lists/Grids From a Child Table

    If I have a parent table "Patient" it has two product tables (Parent Table related 1 <--to--> Many Child Tables) and I make a screen for One Child Table so that it gives me a selection box for the parent table. I can already then
    show on the screen properties of the patient from the table I selected. Can I also bring up a List or Grid of the Other Child Table based on the patient I selected?

    I don't want to display something in the grid. I want to show all of the entries in that grid for a certain person. I want to grab the grid as a control showing all of the properties in a grid not showing them as individual labels or text etc....
    I am not on that entity I am on the orders entity it is already related to the customer to do that to get customer data. The Customer entity/table is related to the allergies entity which is related to Medications to pull up the names of drugs the customer
    is allergic too. I want to pull up the whole grid of allergies as a grid I solved this for now by making a single property on the patient table and grabbing all of the rows for a particular patient. then making them one field. I cannot however grab them as
    a table and have the advantage of the UI of the grid or list functions.

  • SHOW THE PARENT CHILD TABLE RELATIONSHIP TABLE

    hi experts,
    I want show the parent child relation ship tables
    for exmple iam passing the emp table then display related child tables like dept,grade after that again child table(dept,grade) related to child relationship tables like recursive
    Regards,
    VENKAT

    Probably something like below. This may not be exactly what you are looking for, but one way to get what you are asking for.
    Only if you can give specifics, of your Input being passed and the Output, it might be possible to provide more help. But you also need to help us with your best effort on this.
    select *
      from (
            select prior table_name Child, table_name Parent
              from user_constraints
             start with constraint_name = some_constraint_name_of_Parent_Table
            connect by constraint_name = prior r_constraint_name
           ) a
    where a.child is not null;

  • Child table data Recon is not happening

    Hi All,
    I have a requirement to create a custom scheduler in OIM11g, to generate recon events.
    -I have one parent field - which is 'required' in the RO recon mapping
    - Rest 5 fileds are together as one in a child table and again mentioned in RO recon field mappings
    While I am able to generate the recon event, but have not been able to pass the child table data/rows, as together, to the child table data in the recon.
    *********Also I am able to pass child data and generate an event, if I create 5 child tables- one for each field linked to the parent form by using the following methods:
    reconciliationOperationsIntf.createReconciliationEvent(resObjName, usrAttributes,false);
    reconciliationOperationsIntf.addMultiAttributeData()
    reconciliationOperationsIntf.providingAllMultiAttributeData()
    ******However my requirement is to have only one child table- with all the 5 fields as rows in that only one child table (whose recon data then should come in recon event).
    ******I am getting the following error frequently when I am trying to do solve this issue, by using reconciliationOperationsIntf methods
    "Oim Child Table Name is null based on child mapping <fieldname> "
    Kindly tell what approach should be taken to solve this issue. Any general code for the same, posted will be a great help.
    Also tell me if the above issue is some configuration issue with recon mappings or something else.
    Regards

    Hi Suren,
    I am creating recon profile whenever I am doing configuration changes .
    I have mapped the child table--- inside RO-> Object Reconciliation mapping--> Add Field
    I am giving any name to this field, and type as 'multi valued attribute'
    Under this above created field , I have then added the 5 fields of Child table.
    Created recon profile.
    It is still giving the same error as- " oracle.iam.reconciliation.exception.ReconciliationException: Oim Child Table Name is null based on child mapping <Field 1 of the 5 fields>l "
    on encoutering this---
    reconAPI.addMultiAttributeData(eventkey, <Field 1 of the 5 fields>, map)

  • Modify Primary Key Value while present in child tables

    Hi,
    I have one master table having primary key "ESTNO" and 10 child tables having ESTNO as the part of their primary key / composit key. I need to update the value of ESTNO in a master and associated child tables. what should i do to accomplish this...
    Regards.

    I think the trigger is the best solution to a bad problem. Having just tested it, I can confirm that putting the code in the AFTER UPDATE ... FOR EACH ROW trigger does not require us to make the foreign key deferred (at least in 9.2, I assume that also applies in earlier versions).
    Cheers, APC
    ALTER TABLE t2 ADD CONSTRAINT t2t1_fk FOREIGN KEY (col2) REFERENCES t1(col1)
    SQL> CREATE OR REPLACE TRIGGER "APC_LOAD"."T1_AUR" AFTER
      2  UPDATE ON "APC_LOAD"."T1" FOR EACH ROW BEGIN
      3  IF :NEW.col1 <> :OLD.col1 THEN
      4     UPDATE t2
      5     SET t2.col2 = :new.col1
      6     WHERE t2.col2 = :old.col1;
      7  END IF;
      8* END ;
      9  /
    Trigger created.
    SQL> UPDATE t1 SET col1 = 1 WHERE rownum = 1;
    SQL> SELECT count(*) FROM t1 WHERE col1 = 1;
      COUNT(*)
             1
    SQL> SELECT count(*) FROM t2 WHERE col2= 1;
      COUNT(*)
             1
    SQL>  UPDATE t1 SET col1 = 87979 WHERE col1 = 1;
    1 row updated.
    SQL> SELECT count(*) FROM t2 WHERE col2= 1;
      COUNT(*)
             0
    SQL>
    SQL> SELECT count(*) FROM t2 WHERE col2= 87979;
      COUNT(*)
             1
    SQL>        

  • Child table provisioning to SQL using DBAT

    I have a Multivalued attribute named 'AuthzIds' coming from Sun LDAP thru target reconciliation. I wanted to provision this value to SQL's 'MyAuthz' table (Child of MyUser table) using GTC - DBAT.
    USR table -> already provisioned to -> MyUser table
    UD_AUTHZ table -> to be provisioned to -> MyAuthZ table.
    How will I make this child table provisioning work ? Do I have to write any custom adapter ? I see a task 'Child Table UD_MYAUTHZ row inserted" task in SQL_GTC process, which uses a adpSQL_GTC adapter.
    Thanks!
    Kabi

    After Create User User, you'll have to add one more task which will read the data from iplanet user form and add in Child Table using Form APIs.*
    You are suggesting to add a dependent-task to GTC-Process's "create user" task. Is my understanding correct ?
    If yes, this may not work for the following reason.
    I assume GTC task 'create User' invoked when the use is created in SQL. In my use case, users are created in SQL thru auto provisioning during 'iPlanet trusted Recon'. The SQL child table 'MuAuthz' suppose to be provisioned with child data when I run 'iPlanet Target Recon' (not 'trusted Recon'). Because 'target Recon' brings the mutlivalue attribute AuthzId to iPlanet resource UD_AUTHZ table (already associated to OIM Users). I run the 'iPlanet Target Recon' separately after successful completion of 'trustes recon'. So create user may not be the appropriate place for adding this dependent task, since there will be no child data available to OIM user after 'trusted recon' .
    Another question related to this. I see few tasks like "Child Table UD_MYAUTHZ row inserted/ updated/ deleted" in GTC process. What are these tasks used for ?

Maybe you are looking for

  • Remove caches file's automatically if you delete a folder from your drive???

    Gday, First off all sorry for my poor/bad English. When i remove/delete a folder in bridge, where will by the cache file of this folder?? Does it also Remove/delete automatically, ???? Or should I in the preferences box, tick on the (automatically Ex

  • VMware Fusion with XP no longer connects to internet or wireless printer

    I have an IMAC 24" with 4 GB of memory and an intel based platform. Could a recent apple software update (seem to remember ITunes & a security update) on my windows xp virtual machine operated by vmare fusion have caused my internet and networked wir

  • Can you add a PDF file to a DVD?

    Greetings! I have a client that wants to make an electronic brochure for a home listing. I am thinking I can create all the media in Photoshop and make a Slideshow in iPhoto and put it on a DV. Simple. Now, I'd like to also offer him a 4 page brochur

  • Statement.close() Not closing the Result set

    Hi all, I have the following code which invokes a procedure in Oracle database public static callProcedure(Connection connection,String procedure){ ResultSet resultSet = null; CallableStatement callableStatement = null; try { callableStatement = conn

  • Installing on MacBook Air (with no disc drive)

    Hi, I am trying to download Photoshop Elements 10 on my MacBook Air and keep getting the following error: Exit Code: 24 -------------------------------------- Summary -------------------------------------- - 0 fatal error(s), 1 error(s), 0 warning(s)