Getting only the newest records in a Grandchild table

Hi
I have created a new table in the Siebel schema on an Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
This table is called CX_ASSET_XM and is a Grandchild table of S_ASSET
CX_ASSET_XM has a parent table S_ASSET_X
So the structure is like so
S_ASSET  x 1 record
S_ASSET_X x 2 child records
CX_ASSET_XM x 1 grand child records
Therefore the cardinality is one Grandparent can have 2 Grandchild records
This CX_ASSET_XM table will hold information about TCP/IP calls of a Grandchild asset. These calls are not synchronized. therefore one Grandchild asset may make a call today but the other one has not made a call since yesterday.
In my query I find all the grand children records that have been created today (sysdate) and then traverse up the relationship to find the Grandparent, then I traverse back down to find the other twin in the Grandchildren tuple.
The problem with my query is that it returns every single TCP/IP call a pair has made but I only want the most recent callback of each grandchild to analyse
SELECT (cb.SSID), cb.created_by, cb.callback_date, cb.callback_num, asset.desc_text, asset.prom_integ_id, asset.integration_id
--Traversing Up to find the Grandparent record of the
FROM SIEBEL.CX_ASSET_XM cb
    JOIN SIEBEL.S_ASSET_X assetx
      ON cb.SSID = assetx.attrib_37
    JOIN SIEBEL.S_ASSET asset
      ON assetx.par_row_id = asset.row_id
WHERE asset.prom_integ_id IN
--Traversing Down to find the other twin in the pair
(   SELECT asset.prom_integ_id
    FROM SIEBEL.CX_ASSET_XM cb
    JOIN SIEBEL.S_ASSET_X assetx
      ON cb.ssid = assetx.attrib_37
    JOIN SIEBEL.S_ASSET asset
      ON assetx.par_row_id = asset.row_id
ORDER BY cb.callback_date DESC;
e.g. if there are 80 grandchildren which have made two TCP/IP calls that would make a total of 160 records, which is what the query above returns.
However I want 80 records to be returned
e
Grandchildren
Callback Date
1111AAAA (Pair 1)
10-OCT-13
1111AAAB (Pair 1)
09-OCT-13
2222AAAA (Pair 2)
10-OCT-13
2222AAAB (Pair 2)
07-OCT-13
As you can see from the table, atleast one of the pair will have a Callback_Date = Sysdate (Today) which is how I will need to find them in the table before traversing up.
How do I achieve these results. I have tried GROUP BY, DISTINCT, ROWNUM = 1

Hi,
968432 wrote:
Sorry for my ignorance but how do I incorporate the ROW_NUM function into my query, or will it be a new query from scratch.
When you say partition, does that mean the partition would be between my traversal up the tables to the grand parent and then back down again?
You can use ROW_NUMBER with something very much like your existing query; there's no need to start from scratch; you just won't repeat the joins in the WHERE clause.  You'll just be joining the tables once.  If it really helps you to think of traversing either up or down, then go ahead, but you mind find it simpler just to think of joining.  Every row of the join will include some expression(s) that uniquely identifies the grandparent; that's what you'll PARTITION BY.
It would be a lot easier to explain and to understand if we had some sample data and desired results.  Either post CREATE TABLE and INSERT statements for a little sample data, or phrase the question in terms of tables that anybody with Oracle probably has, such as those in the hr schema.  (People in hr.employees are related to deparatments in hr_departments, and departments are related to places in hr.locations, so location is the grandparent of employee.  If you knew how to find the most recently hired employee from each location in the hr schema, then you'd know how to solve your problem in your schema.  For example, if you wanted these results:
CITY                 DEPARTMENT_ID EMPLOYEE_ID LAST_NAME  HIRE_DATE
London                          40         203 Mavris     07-Jun-2002
Munich                          70         204 Baer       07-Jun-2002
Oxford                          80         167 Banda      21-Apr-2008
Seattle                        100         113 Popp       07-Dec-2007
South San Francisco             50         128 Markle     08-Mar-2008
Southlake                       60         104 Ernst      21-May-2007
Toronto                         20         202 Fay        17-Aug-2005
you could get them like this:
WITH  got_r_num  AS
    SELECT  l.city
    ,       d.department_id
    ,       e.employee_id, e.last_name, e.hire_date
    ,       ROW_NUMBER () OVER ( PARTITION BY  l.city
                                 ORDER BY      e.hire_date  DESC
                               )   AS r_num
    FROM    hr.employees    e
    JOIN    hr.departments  d  ON   d.department_id  = e.department_id
    JOIN    hr.locations    l  ON   l.location_id    = d.location_id
SELECT  city
,       department_id
,       employee_id, last_name, hire_date
FROM    got_r_num
WHERE   r_num = 1

Similar Messages

  • Pickup only the newest record in an Internal Table.

    Hi all:
    I have and internal table that i am accesing in a transformation.
    Which is the best approach to read from the internal table only the
    record with the newest date. Data look like this:
    Date_________MAT___ Qty
    12.08.2009___4050___70
    10.05.2009___4050___30
    18.11.2009___4050___42
    20.07.2009___4050___28
    In this case, for Material 4050 i need only the third record (18.11.2009),
    any code example or guideline..?
    Regards,

    Hi,
    You can sort the internal table by date and material in descending order and then perform read on the internal table with key as material. this would bring the latest date for that material.
    Regards,
    Rk.

  • How to get only the latest record in a folder

    Hi all,
    We have an OA SIT that is not a "standard" SIT in that it does not have the traditional Begin and End date. It only has an Effective date. Is there some way I can filter this table to only give me the latest record in the series? I know how to do this in SQL, but don't see how it would be possible in the EUL.
    We're trying to avoid creating database views, but at this point, I'm thinking it may be the easiest way to address this. Any other suggestions?
    Thanks in advance,
    Jewell

    Jewell.
    Of course I'm not going to mention that I have no idea what a 'standard' SIT is compared to your basic 'non-standard' SIT ... and I have to watch my spelling of such ... but however ...
    As you're most likely aware, in SQL you would get all the 'standard' SIT records first by going through the table. Then you'd go back through them all and find the most recent one.
    Because of this 2 table pass, I agree that just putting the SQL code in a custom folder (as you're not using views) would make the most sense.
    Russ

  • How can I get only the last 2 rows?

    How can I narrow down a query to get only the last two rows in a table ?
    Thanks,
    Mohan

    Thanks a lot Ram for your suggestion but already I have a query which returns a set of rows, of which I would like to further filter and get the last two rows
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Ramanuj Bangad ([email protected]):
    try out something like this if it helps.
    Example:
    select * from users
    where rownum <= (select count(*) from users)
    minus
    select * from users
    where rownum <= (select count(*) -2 from users )
    <HR></BLOCKQUOTE>
    null

  • Getting a "Displaying only the newest results below. To view all results, narrow your query by adding a filter" message in error

    I have a list with almost 10000 items. I have a view that should be returning 8 items. For me, the Farm Admin, I see the full set of expected values. The message "Displaying only the newest results below. To view all results, narrow your query by
    adding a filter" shows for other users. This makes no sense -
    there ARE filters on this view. I'd rather not increase the throttle limit.
    Anthony Kelly

    Hi Ajk,
    Check that the list is not scoped by an audience; but, I'm afraid that either way admin, (e.g. non Farm admin or site collection admin)
    I'd recommend exporting to excel, create two new spreadsheets and then import as custom lists.
    Best of luck and cheers,
    Stacy Anothersharepointblog.blogspot.com

  • Getting only a few records at a time.

    Using a Select * from. Is there an option where I get only so many records. This is for a console application. I wanted some thing where it will display only 3 records at a time. And then I have the option of viewing the next 3 and then the next 3 records
    and so on.
    Any one have any ideas.
    Merry Christmas EVERY ONE and thanks to all the members on msdn forums for helping me with my code.
    Joe Moody
    http://www.starfiresoft.com
    Pro-Forums
    Delta Force Barracks
    On the Frontlines

    Thanks. It doesn't matter as long as I can get it to work. The idea is to display 3 records at a time. Then the user should be able to go backward or forward in the list. Let me show you what I have. This will give you some idea on how I have it displaying
    the info.
    SqlCeCommand cm = new SqlCeCommand("SELECT * FROM users", cn);
    //cm.Parameters.AddWithValue("@tooid", num);
    //cm.Parameters.AddWithValue("@fromid", Id);
    SqlCeDataReader rd = cm.ExecuteReader();
    try
    while (rd.Read())
    Door.CursorRight(10);
    Door.WriteLn("|0C___________________________________________________");
    Door.CursorRight(10);
    Door.WriteLn("|0FId |04: |03" + rd["Id"].ToString() + " |0FName |04: |03" + rd["username"].ToString());
    Door.CursorRight(10);
    Door.WriteLn("|0FStatus |04: |03" + rd["status"] + " |0FDate Jointed |04: |03" + rd["joindate"]);
    Door.CursorRight(10);
    Door.WriteLn("|0C___________________________________________________");
    catch (Exception e)
    throw new Exception(e.Message);
    cn.Close();
    This is inside of a do loop. and at the bottom I have it waiting for user input. or the user can quit and return to the main menu.
    Door.WriteLn();
    Door.Write("|07Page |0F<|04||0F> |0FQ|09)|0BQuit |07Choice |04: |0C");
    cc = Char.ToUpper(Door.ReadKey());
    Above is my prompt. This waits for user input. and I use a switch to tell the software what to do. Any way if you want to know what Door.writeLn() is, Think of it like this "Console.Writeline()". This is just a library I use for the kind of programming I
    do.Any help would be great. Thanks and have a safe Xmas.
    Joe.
    http://www.df-barracks.com Delta Force Barracks
    http://www.starfiresoft.com Starfire Software

  • Display only the last record per material in SAP query

    Hi,
    I have created a SAP Query using the quickviewer that is a join between 2 tables (MSEG and MKPF) that consist of material document information and date of posting.
    The results are fine however I would like only the last record per material to be displayed.
    Can anyone tell what do I need to add so for only the last record per material be displayed in the output.
    Thanks,
    Mark

    Hi Mark,
    May be if you use Control Level processing .........I think you will be able to get the result you want. Try displaying as Below,
    LOOP AT XXXXX.
    AT FIRST material.
    ENDAT.
    AT LAST material.
    *...Display what ever you want here. It will display at end of every material.
    ENDAT.
    ENDLOOP.
    Before using sort the table with key material in ascending.
    Hope what I had to say is helpful to you.
    Cheers,
    Raga Suman.

  • Displaying only the newest results below. To view all results, narrow your query by adding a filter.

    Hi,
    In one of my list there are 33,000 records.
    It gives message "Displaying only the newest results below. To view all results, narrow your query by adding a filter."
    I don't want to change my threshold limit. Can anybody please tell me steps to resolve this issue?
    Regards,
    Amit Khatri

    I have a list of 11,000 items. Even though I have setup filters on it and it shows all 10 records based on that filter, it still shows that warning on top. For some items, even with those filters, I don't see the list items at all. How do I deal with
    this situation. I don't want to change my threshold limits from CA either. Please help.
    MAK

  • How to get the last record of an internall table ....

    Hi All..
    i want to get the last record of an internal table itab, and i want the the value of the last record.

    Hi,
         Use describe statment.
    data: lv_line type i.
        Describe table itab lines lv_line.
        read table itab into wa_itab index lv_line.
    regards,
    Santosh Thorat

  • How can I get only the music I want onto my iPhone using iTunes Match

    how can I get only the music I want onto my iPhone using iTunes Match?  At present it is putting a random selection on; it has none of the same control as iTunes on my Mac.  And although I uploaded all my album artwork to iCloud, it is not transferring it back to my iPhone

    Iphone are meant to be sync to one itunes library only.
    You can copy those songs to a cd and then put a copy to your itunes media library.

  • Get only the filename not the full path of the file.

    hi to all..
    how can i get only the filename of the file not the full path and to be placed on a textinput.?
    example:
    when i'browse the file and select sample.txt
    "C:\Users\user\Desktop\folders\sample.txt" this will be inputted on the textinput.
    however, what i want to have is when i'browse and select a file..
    textinput should only contain "sample".
    does anyone knows how to do it?

    Hi cyrus@adobe,
    How are you getting the full path of the file when you browse, I dont think for security reasons the Flash Player will aloow to do so. You can only get the file name not the full path of the file when you browse.
    Are you using Flex4..?? I am not sure whether this is possible in Flex4..However if you are getting full path and if you wanted to show only the filename then you can just use theString class split function to acehive this..
    var fullPath:String = "C:\Users\user\Desktop\folders\sample.txt";
        var splitPath:Array = fullPath.split("\");
        textInput.text = splitPath[splitPath.length-1];
    Thanks,
    Bhasker

  • Home to get only the file name ?

    I m trying to get only the filnames without the path
    if( myDir.exists() && myDir.isDirectory()){
                  File[] files = myDir.listFiles();
                       for(int i=0; i < files.length; i++){
                            if (files.getName().indexOf(".xml") == -1)
                             continue;
                        System.out.println(files[i]);

    You answered your question
    files.getName().                                                                                                                                                                                                       

  • Get Only the direct children by name

    Hello all!
    Is there a way in JAXP to get only the direct children by name, as oppose to Element.getElementsByTagName(String name) that returns all the children with the given name of all descendant (not just of this one).
    Thanks in advance,
    Alon.

    The JAXP API doesn't define a method for this. You can implement your own quite easily:public Vector getChildrenByTagName(Node parent, String name){
      NodeList children = parent.getChildNodes();
      Vector childMatches = new Vector();
      Node child;
      for(int i=0; i<children.getLength(); i++){
        child = children.item(i);
        if((child.getNodeType() == Node.ELEMENT_NODE) && ((Element)child).getTagName().equals(name)) childMatches.add(child);
      return childMatches;
    }

  • To get only the error messages???

    Hi,
    When i compile my java code i am getting warning errors also . Is there anyway to get only the error messages only, not the warning using
    javac or java???
    Thanks,
    JavaCrazyLover

    javac <option> <sourcefile>. if you use[b] -nowarn option you get only error message.
    if in the shell invoke only the command javac without option and sourcefile you see all option available. Bye

  • How to get only the first level of nodes for a subform?

    How can we get only the first level of nodes of a subform?
    For ex:
    Form1
         SubForm1
              Text1
              Text2
              RadioButton1
         SubForm2
              Text1
              Text2
              RadioButton1
         SubForm3
              Text1
              Text2
                   SubForm31
                        RadioButton1
    In this heirarchy if we give Form1.nodes will refer to all nodes under the Form1 (SubForm1,Test1,Text2,RadioButton1,SubForm2,...SubForm31, RadioButton1 etc..)
    But is there any way that we can access only the first level of nodes of Form1 ie can we get only (SubForm1,SubForm2,SubForm3) for Form1 in any Way..?
    Thanks.

    Two ways .....
    1. Use Javascript E4X instead ...there are nice functions for getting children of parents.
    2. Cycle through all of the form1.nodes and look for objects that have a className of "subform". For loops are useful for this task.
    Make sense?
    Paul

Maybe you are looking for

  • KVM for mixed DVI D-sub setup

    I can't find one of the KVM discussions I recall, but I don't think it addressed this. I would love to share a keyboard, mouse, and one or more monitors with my 3 PCs.  But the laptop and one PC are old (meaning D-sub video outputs), and the other is

  • Password Aging & Account Lockout in ACS 4.2

    I have a requirement that in ACS the  user accounts should get disabled after 1 day , so in the group setting under the Password Aging Field I configured the same as 1 day , the Grace & Warning Period is 0 days I want that all these user accounts wou

  • MacBook running 10.7.5  MacBook pro  10.4.11  Compatibility question?

    I have a macbook running 7.5  Just bought a used macbook pro that has 10.4.11  I called apple and bought a 10.6 update disk - it is about a week out due to shipping - I just backed up the macbook running 10.7.5  with carbon copy cloner I connected th

  • What is thes best 5.1 speaker kit for macbook pro 2011

    what is the best 5.1 speaker kit for my macbook pro thanks for help.

  • I currently also have AVG 9.0.920. Is Fire Fox 8 compatable with this

    I currently have AVG 9.0.920 installed on my desk top. If I download Fire Fox version 8, will it affect my AVG program. I seem to have seen something in the past where newer versions of Fire Fox affect certain aspects of my version of AVG and that I