Most recently inserted record

how can i get most recently inserted record?
note: there is no date columns.

It's possible, but not probable (given how your table is likely created).
TUBBY_ORCL?create table not_likely
  2  (
  3    column1 number
  4  )
  5  rowdependencies;
Table created.
Elapsed: 00:00:00.01
TUBBY_ORCL?
TUBBY_ORCL?begin
  2    for i in 1 .. 100
  3    loop
  4      insert into not_likely values (i);
  5      commit;
  6    end loop;
  7  end;
  8  /
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.03
TUBBY_ORCL?
TUBBY_ORCL?select *
  2  from not_likely
  3  where ORA_ROWSCN =
  4  (
  5    select
  6      max(ORA_ROWSCN)
  7    from not_likely
  8  );
           COLUMN1
               100
1 row selected.
Elapsed: 00:00:00.01Uses the pseudo column ORA_ROWSCN which increments with each commit performed against the table (as i've enabled row dependencies, otherwise it would track at the block level).
Assuming you don't have row dependencies enabled on your table, you could consider using flashback query if you know roughly when you are trying to compare to.
All in all ... if you need to do this for part of the application design, then you need to do more design work on the structures at hand.

Similar Messages

  • Most recently inserted row

    Hi,
    I have a table with a composite key on it's 4 columns(a,b,c,d). and i have another column called timestamp, which is used to identify when a record is inserted into the table.
    how to query which record is most recently inserted ?
    Any help is appriciated
    Thanks
    greddy

    or, this:
    SQL> select * from (select * from emp order by hiredate desc) where rownum = 1 ;
         EMPNO ENAME      JOB              MGR HIREDATE           SAL       COMM     DEPTNO
          7876 ADAMS      CLERK           7788 23-May-1987       1100                    20
    1 row selected.
    SQL>

  • Most recently entered records

    Hi, I have table like below. I would like to return most recently entered records in the output.
    I am able to write the query for most recently entered records, but i want to include all the table columns in the output.
    can someone give me idea to write the query or view?
    Thanks for help.
    create table foo_a
              Key varchar2(10),
              Attr varchar2(100),
              Val varchar2(100),
              EntryDate date,
              EndDate date,
              EFDate date,
              ETDate date
    DATA IN THE TABLE:
    FS.1 || AAA || 200     || 31-DEC-2005 ||     31-DEC-2005 || 31-DEC-2005     || 31-DEC-2005
    FS.1 || AAA     || 250     || 30-DEC-2005 || 31-DEC-2005 || 31-DEC-2005     ||     31-DEC-2005
    FS.2 || BBB     || 300     || 12-JAN-2005 || 31-DEC-2005 || 31-DEC-2005     ||     31-DEC-2005
    FS.1 || AAA     || 350     || 01-JAN-2006 ||     31-DEC-2005 || 31-DEC-2005     ||     31-DEC-2005
    FS.3 || CCC     || 200     || 09-FEB-2006 ||     31-DEC-2005 || 31-DEC-2005     ||     31-DEC-2005
    FS.3 || XXX     || 100     || 09-FEB-2006 ||     31-DEC-2005 || 31-DEC-2005     ||     31-DEC-2005
    FS.3 || YYY     || 100     || 10-FEB-2006 ||     31-DEC-2005 || 31-DEC-2005     ||     31-DEC-2005
    FS.3 || XXX     || 120     || 10-FEB-2006 ||     31-DEC-2005 || 31-DEC-2005     ||     31-DEC-2005
    FS.4 || aaa     || 'H'     || 02-FEB-2006 ||     31-DEC-2005 || 31-DEC-2005     ||     31-DEC-2005
    FS.4 || aaa     || 'H'     || 11-FEB-2006 ||     31-DEC-2005 || 31-DEC-2005     ||     31-DEC-2005
    QUERY:
    select
         Key,
         Attr,
         max(EntryDate)
    from
         foo_a
    group by
         Key,Attr
    OUTPUT FOR THE ABOVE QUERY:
    KEY     ATTR     MAX(EntryDate)
    FS.1 || AAA || 1/1/2006      
    FS.2 || BBB || 1/12/2006      
    FS.3 || CCC || 2/9/2006     
    FS.3 || XXX || 2/10/2006      
    FS.3 || YYY || 2/10/2006      
    FS.4 || aaa || 2/11/2006      
    OUTPUT I WANT IS:
    KEY     ATTR     MAX(EntryDate)          ENDDATE          EFDATE               ETDATE
    FS.1 || AAA || 1/1/2006 || 31-DEC-2005 || 31-DEC-2005 || 31-DEC-2005
    FS.2 || BBB || 1/12/2006 || 31-DEC-2005 || 31-DEC-2005 || 31-DEC-2005
    FS.3 || CCC || 2/9/2006 || 31-DEC-2005 || 31-DEC-2005 || 31-DEC-2005
    FS.3 || XXX || 2/10/2006 || 31-DEC-2005 || 31-DEC-2005 || 31-DEC-2005
    FS.3 || YYY || 2/10/2006 || 31-DEC-2005 || 31-DEC-2005 || 31-DEC-2005
    FS.4 || aaa || 2/11/2006 || 31-DEC-2005 || 31-DEC-2005 || 31-DEC-2005

    See the following link for a great discussion of this topic:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:2165134263446

  • Return most recent matching record on Sub Report

    I am hoping there is an easier way to go about this.
    REPORT 'A': I have already made a report (which will inevitably be a subreport) that only reports the first record of each Group2 (I used a counter formula and conditional suppress.)  This enabled me to have a report full of only the most recent records.
    As an example, let's say this first report contains Account#, Price, and Invoice Date (again, it only reports the most recent Invoice Date and corresponding price and account # - the other records for each account are supressed).
    REPORT 'B': I have another report with Account Numbers and Category Numbers.
    I want to Match the Account Numbers, lookup the numbers on the original report ('A'), and return the recent Prices and Invoice Dates to the 2nd report ('B').  So that Report B has Account#, Category#, Most Recent Price, & Most Recent Invoice Date.
    A subreport has been my only idea because again, I only want the most recent prices from 'A' to report on 'B'.  Any help is appreciated.
    Edited by: Mara Nowak on Sep 4, 2008 9:39 AM

    Mara,
    If Report B is the main report then I would suggest grouping on the same field as you used in Report A for Group 1. Place the subreport, Report A, in the GH1 and link it based on the Group 1 field. The subreport will then only display data for the same group instance.
    If you need to use the most recent data or price in Report B then assign those values to shared variables in the subreport and reference them in formulas in the main report in a section below where the subreport resides, GH1.

  • How to get most recent consecutive records with the same value

    Hi,
    Can someone please help me to solve my problem?
    Below is my table
    Prod_Code-----Purchase_date---Inv_number-------Inv_amt
    MS_AV16850------18/01/2005-----------6575947----------------7.93
    MS_AV16850------22/07/2005-----------7034012----------------51.82
    MS_AV16850------04/01/2006-----------8719618----------------51.82
    MS_AV16850------20/06/2006-----------9515864----------------104.69
    MS_AV16850------16/04/2007-----------10353759----------------189.29
    MS_AV16850------30/05/2007-----------10689899----------------189.29
    MS_AV16850------06/01/2008-----------1653821----------------65.49
    MS_AV16850------22/02/2009-----------10866311----------------189.29
    I want my query to show the rows that has most recent purchase dates with same amount in consecutive purchase date.
    So from the table above, the query should display:
    Prod_Code-----Purchase_date---Inv_number-------Inv_amt
    MS_AV16850------16/04/2007-----------10353759----------------189.29
    MS_AV16850------30/05/2007-----------10689899----------------189.29
    It should not get
    MS_AV16850------16/04/2007-----------10353759----------------189.29
    MS_AV16850------30/05/2007-----------10689899----------------189.29
    MS_AV16850------22/02/2009-----------10866311----------------189.29
    because inv_number 10866311 has a prvevious inv_amount of 65.49.
    and not get this
    MS_AV16850------22/07/2005-----------7034012----------------51.82
    MS_AV16850------04/01/2006-----------8719618----------------51.82
    because they are not the most recent purchase date even if they have the same inv_amount.
    Thanks in advance.

    Hi,
    You're right; thanks for catching my mistake.
    I changed the WHERE clause of the main query (including subquery there) to deal with that situation:
    WITH     got_grp          AS
         SELECT      x.*
         ,      ROW_NUMBER () OVER ( ORDER BY      purchase_date )
                - ROW_NUMBER () OVER ( PARTITION BY  inv_amt
                                             ORDER BY         purchase_date )     AS grp
    --     ,      ROW_NUMBER () OVER ( ORDER BY      purchase_date )     AS r1
    --     ,        ROW_NUMBER () OVER ( PARTITION BY  inv_amt
    --                                         ORDER BY         purchase_date )     AS r2
         FROM     table_x     x
    SELECT     *     -- Or list all columns except grp
    FROM     got_grp
    WHERE     (inv_amt, grp)  IN  (
                               SELECT    MAX (inv_amt) KEEP (DENSE_RANK LAST ORDER BY MAX (purchase_date))
                        ,       MAX (MAX (grp))
                                FROM      got_grp
                                GROUP BY  grp
                                ,       inv_amt
                                HAVING    COUNT (*)     > 1
    ;Thanks, too, for posting the sample data. Apparantly, you're more interested in solving this problem than OP is.
    Edited by: Frank Kulash on Nov 22, 2010 1:36 PM
    The r1 and r2 columns are not needed for the solution. You may want to display them, just to help see how the query works.

  • Retrieve the most recent history records from a history table

    I have a table which stores movement of applications or files. There could be any number of history records for any file in this table. I can know who has a given file right now by using max(date) and the unique id field using the query below:
    SELECT IS_WITH FROM APPLICATION_MOVEMENT WHERE DATE_SENT = (SELECT MAX(DATE_SENT) FROM APPLICATION_MOVEMENT WHERE APPLICATION_ID = 461)
    However, my problem is, I want to return a list of all the files and who has them currently, how can I get this....i cannot enter the APPLICATION_ID anymore....
    Table Name: APPLICATION_MOVEMENT
    Field 1: IS_WITH
    Field 2: DATE_SENT
    Field 3: APPLICATION_ID

    This?
    WITH application_movement AS
    SELECT 1 application_id, 'Greg' is_with, to_date('01-jan-07') date_sent FROM dual
    UNION ALL
    SELECT 1 application_id, 'Steve' is_with, to_date('01-feb-07') date_sent FROM dual
    UNION ALL
    SELECT 2 application_id, 'Bill' is_with, to_date('01-feb-07') date_sent FROM dual
    UNION ALL
    SELECT 2 application_id, 'Fred' is_with, to_date('01-mar-07') date_sent FROM dual
    UNION ALL
    SELECT 2 application_id, 'Jim' is_with, to_date('01-apr-07') date_sent FROM dual
    SELECT DISTINCT application_id,
           FIRST_VALUE(is_with) OVER (PARTITION BY application_id ORDER BY date_sent DESC),
           max(date_sent) OVER (PARTITION BY application_id)
    FROM   application_movement;
    APPLICATION_ID FIRST MAX(DATE_
                 2 Jim   01-APR-07
                 1 Steve 01-FEB-07Greg

  • Need to retrieve the most recent record per deposit number

    Can someone please show me a way to solve my problem or at least point me in the right direction.
    I have a simple bibliography table called mdd_biblio that has 3 fields:
    bib_mdd_no this is a deposit number
    bib_upd_by person who updated the record
    bib_upd_date date the record was updated (timestamp)
    A deposit might have more than one bibliographic entry with either the same date or a newer date and, the deposit might have one or more person updating the bibliography
    The table has 4974 records but only 1867 are unique deposit numbers
    All I want to do is select a single record that indicates when the deposit was last edited and and who did the editing (as indicated by the *). I don't care which record it is as long as it is the most recent date.
    The following query retrieves 1944 records (67 duplicates) and has eliminated 3000 duplicates but hasn't eliminated them all. Why?
    select unique(bib_mdd_no), bib_upd_by, bib_upd_date from mdd_biblio
    order by bib_mdd_no
    M64C/16-001 MDD 13-SEP-07 *
    M64C/16-001 MDD 13-SEP-07
    M64C/16-002 DPROUXE 30-NOV-07 *
    M64C/16-002 MDD 13-SEP-07
    M64C/16-002 MDD 13-SEP-07
    M64C/16-003 DPROUXE 29-NOV-07 *
    M64C/16-003 MDD 13-SEP-07
    M64C/16-003 MDD 13-SEP-07
    M64C/16-004 MDD 13-SEP-07 *
    M64C/16-004 MDD 13-SEP-07
    M64C/16-005 MDD 13-SEP-07 *
    M64C/16-005 MDD 13-SEP-07
    M64C/16-006 DPROUXE 03-DEC-07 *
    M64C/16-006 MDD 13-SEP-07
    M64C/16-007 MDD 02-OCT-07 *
    M64C/16-008 MDD 02-OCT-07 *
    M64C/16-009 MDD 02-OCT-07 *
    M64C/16-010 MDD 02-OCT-07 *
    I don't understand why of these duplicates still show up here since 3000 have been eliminated..
    To Reiterate: What I really need is a simple query to retrieve the most recently edited record for each deposit number regardless of the updater's name. I need this in order to build a summary table from this and 15 other tables.
    Thanks for any help you can give
    Glenn

    Usually it is done somehow like this
    select bib_mdd_no,
           bib_upd_by,
           bib_upd_date
      from (select bib_mdd_no,
                   bib_upd_by,
                   bib_upd_date,
                   row_number() over (partition by bib_mdd_no order by bib_upd_date desc) r
              from mdd_biblio
    where r = 1
    order by bib_mdd_noRegards
    Etbin

  • How to determine most recent date from the date column of internal table

    Dear friends
    would you like to tell me. how i determine the most recently changed record by looking at date and time from internal table i am not supposed to sort the table by date and time... I must check date and time with other records date and time to determine which record is most recently changed...
    here the scenario is.
    id idnumber chdate chtime
    1 123456 20060606 135312
    2 123456 20060606 135900
    3 123456 20060606 132300
    4 123457 20060606 140000
    5 123457 20060606 142500
    in the above scenario i must keep in my mind that the most recently changed record is identical to its idnumber i can say that:
    the record should be fetched this way
    id idnumber chdate chtime
    3 123456 20060606 132300
    5 123457 20060606 142500
    because here the id 3 is the most recently changed in the idnumber 123456
    where id 5 is the most recently changed in the idnumber 123457
    please help me to determin how i am supposed to carry out this task any suggestion, code will be great help of mine.
    regards
    Naim

    After testing my suggestion above, I realized that it doesn't work because the delete adjacent actually will keep the first one and delete the rest.  I'm working with Srinivas's code a bit now,  I think it is almost what you want.  I am under the impression that you dont' want to HIGHest date/time, but just the last record of the sequence, if this is the case, then this code will help.  Here we will assign an index to each record per the idnumber, that way we can sort it and get the lastest record.
    report zrich_0001.
    types: begin of itab_type,
            id       type i,
            idnumber type i,
            chdate   like sy-datum,
            chtime   like sy-uzeit.
    types: end of itab_type.
    types: begin of itab_type2,
            id       type i,
            idnumber type i,
            index    type i,
            chdate   like sy-datum,
            chtime   like sy-uzeit.
    types: end of itab_type2.
    data: itab     type table of itab_type with header line,
          itab2    type table of itab_type2 with header line,
          prev_rec type itab_type.
    data: v_id type i.
    start-of-selection.
      itab-id       = 1.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '135312'.
      append itab. clear itab.
      itab-id       = 2.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '135900'.
      append itab. clear itab.
      itab-id       = 3.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '142500'.
      append itab. clear itab.
      itab-id       = 4.
      itab-idnumber = 123457.
      itab-chdate   = '20060606'.
      itab-chtime   = '140000'.
      append itab. clear itab.
      itab-id       = 5.
      itab-idnumber = 123457.
      itab-chdate   = '20060606'.
      itab-chtime   = '120000'.
      append itab.
      clear itab.
    <b>  data: counter type i.
    * Assign an index to each row per idnumber
      loop at itab.
        on change of itab-idnumber.
        if sy-tabix > 1.
          clear counter.
          endif.
        endon.
        clear itab2.
        move-corresponding itab to itab2.
        counter = counter + 1.
        itab2-index = counter.
        append itab2.
      endloop.
    * Sort it and get rid of older records.
      sort itab2  by idnumber ascending
                     index descending.
      delete adjacent duplicates from itab2 comparing idnumber.</b>
      read table itab2 with key idnumber = '123456'.
      write:/ itab2-chdate, itab2-chtime.
      read table itab2 with key idnumber = '123457'.
      write:/ itab2-chdate, itab2-chtime.
    Regards,
    Rich Heilman

  • Select record having most recent date

    Table: Order
    Code     ImportId     EntryDate
    1 100
    10/11/2014
    1 101
    10/14/2014
    1 102
    10/10/2014
    2  103  10/11/2014
    2   104  10/15/2014
    I want to select the record having the most recent EntryDate grouped by Code. In the select, i need to return the ImportId.
    Anonymous

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Nothing you posted
    was right. Temporal data should use ISO-8601 formats. This is the only format allowed in the ANSI-ISO SQL Standards and it is the most common IT standard on Earth; but you do not know it! 
    Code should be in Standard SQL as much as possible and not local dialect. There is no such crap as a generic “code” in RDBMS. Table have keys, so you have no table! Rows are not records; this is a basic concept. 
    This is minimal polite behavior on SQL forums. Here is my guess at what a polite, competent person might have posted. 
    CREATE TABLE Import_Orders
    (order_type INTEGER NOT NULL
     CHECK(order_type IN (1,2)),
     import_id CHAR(3) NOT NULL PRIMARY KEY, 
     entry_date DATE NOT NULL);
    INSERT INTO Import_Orders
    VALUES
    (1, 100, '2014-10-11'),
    (1, 101, '2014-10-14'),
    (1, 102, '2014-10-10'),
    (2, 103, '2014-10-11'),
    (2, 104, '2014-10-15');
    I want to select the record [sic] having the most recent entry_date grouped by order_type. In the select, I need to return the import_id.
    If you return only the import_id, then the most recent entry_date does not matter! Think about it! Did you want the whole row with the most recent entry_date? Here is a common idiom. 
    WITH X (import_id, order_type, entry_date, entry_date_max)
    AS
    (SELECT import_id, order_type, entry_date, 
            MAX(entry_date) OVER (PARTITION BY order_type)
       FROM Import_Orders) 
    SELECT import_id, order_type, entry_date
      FROM X
     WHERE entry_date = entry_date_max;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Remove the duplicate rows but keep the most recent and oldest records

    I have a Product table, some products have duplicate rows(same productID). I want to keep the most recent and the oldest records based on ETL load date (or min and max productKey), delete others. How to do this in a simple way?
    ProductKey | ProductID |ETL_Load_Date
    1001 | 501 | 2014-01-01
    1002 | 501 | 2014-01-02
    1003 | 501 | 2014-01-03
    1011 | 502 | 2014-01-01
    1012 | 502 | 2014-01-02
    1013 | 502 | 2014-01-03

    declare @table table (ProductKey int, ProductID int, ETL_Load_Date date)
    insert @table (ProductKey, ProductID, ETL_Load_Date)
    values
    ( 1001 , 501 , '2014-01-01' ), ( 1002 , 501 , '2014-01-02' ),
    ( 1003 , 501 , '2014-01-03' ), ( 1011 , 502 , '2014-01-01' ),
    ( 1012 , 502 , '2014-01-02' ), ( 1013 , 502 , '2014-01-03' )
    SELECT *
    FROM @table t
    INNER JOIN (
    SELECT MIN(etl_load_date) min_load_date, MAX(etl_load_date) max_load_date, ProductID
    FROM @table
    GROUP BY ProductID
    ) m
    ON t.ProductID = m.ProductID
    AND t.ETL_Load_Date IN (min_load_date,max_load_date)
    This will show both the min and max load dates, for each ProductID
    Thanks to Saeid for posting some test objects.

  • How can i display recent update/delete/insert records in form

    Hai !!!!
    i am new for forms,.......any body tell me, how can i display recent no of records updated or no of records deleted or no of records are inserted in a form. these records count are display in display items....give me detail explination......
    Subbu.....

    the easiest way is copy and paste the oracle-forms example from the OU.
    You need form-level-trigger ON-ERROR + ON-MESSAGE, POST-INSERT, POST-UPDATE, POST-DELETE, three global variables and a procedure:
    ON-ERROR
    handle_message( error_code, 'ERROR: ' || ERROR_TYPE || '-' || TO_CHAR(ERROR_CODE) ||': '|| ERROR_TEXT );
    ON-MESSAGE
    handle_message( message_code, MESSAGE_TYPE || '-' || TO_CHAR(MESSAGE_CODE) || ': ' || MESSAGE_TEXT );
    PROCEDURE handle_message( message_number IN NUMBER, message_line IN VARCHAR2 ) IS
    BEGIN
        IF message_number IN ( 40400, 40406, 40407 )
        THEN
          DEFAULT_VALUE( '0', 'GLOBAL.insert' );
          DEFAULT_VALUE( '0', 'GLOBAL.update' );
          DEFAULT_VALUE( '0', 'GLOBAL.delete' );
          MESSAGE('Save Ok: ' ||
            :GLOBAL.insert || ' records inserted, ' ||
           :GLOBAL.update || ' records updated, ' ||
           :GLOBAL.delete || ' records deleted !!!' );
          ERASE('GLOBAL.insert'); 
          ERASE('GLOBAL.update');
          ERASE('GLOBAL.delete');
        ELSE
             MESSAGE(message_line );
              END IF;
    END;
    POST-INSERT
    DEFAULT_VALUE('0', 'GLOBAL.insert');
    :GLOBAL.insert := TO_CHAR( TO_NUMBER( :GLOBAL.insert ) + 1 );
    POST-UPDATE
    DEFAULT_VALUE('0', 'GLOBAL.update');
    :GLOBAL.update := TO_CHAR( TO_NUMBER( :GLOBAL.update ) + 1 );
    POST-DELETE
    DEFAULT_VALUE('0', 'GLOBAL.delete');
    :GLOBAL.delete := TO_CHAR( TO_NUMBER( :GLOBAL.delete ) + 1 );try it
    Gerd

  • Select "most recent" records in abap

    Hi
    how can I select the most recent records in a table by using the abap select statement.
    Example: The 100 rows with the "highest" (most recent) sequence-numbers in a table with documents.
    somehow like this:
        SELECT "most recent" * FROM draw
        INTO TABLE gt_doklist
        UP TO 100 ROWS
        where ...
    Has anybody an idea?
    Thanks in advance,
    Willi

    Actually I believe that all the answers are wrong.
    I believe that there will never be a single statement. If you need to determine the last 100 records for a special user you first need to determine the highest document number.
    this can be done by
    select max( document_number ) into document_number from table where username = username.
    Any descending sorting order or group by etc. will never make sure that you get the last one. For a simple reason What should the select statement look like that makes sure (in combination of any cursor applied)? Its impossible!
    If you now need the latest 100 records for a single user its the same problem like buffered number ranges. There is no way to perform that task because there is no database routine or sql statement to do so. And 1.5 million records are too much to try out or select everything.
    You could do an assumption that the last 100 for that user have been posted during the last 1000 or last 10.000 records, select them and filter out.
    Alternative you can perform the following select statement for 100 times. Using an index on document number and user might not be such a performance killer if its only done for one user during his online dynpro process:
    data: max_number type char10.
    select max( documentnumber ) into max_number from table
      where username = username into [structure].
    max_number = max_number + 1.
    do 100 times
    select max( documentnumber ) from table intomax_number
      where username = username and docnumber lt max_docnumber.
    select * from [db_table] into [structure] where docnumber = max_number.
    append [structure] to [table].
    enddo.
    Of course that just draft coding... apply if statements and so on...
    Even though its pretty poor, its the only way to do. Any select statement will never garantee what records you will get if you do not restrict accordingly and if the restriction has to be made on document number, but if there is no way to get the max_number - [100 last records of this user], there is no solution using one statement.
    Thats it.
    Edited by: Rob Burbank on Feb 25, 2010 8:52 AM

  • Seelcting records with most recent date

    Hello Friends
    I am new to this group.
    I am having a set of records as follows in a table
    col1,col2, col3(dd/mm/yyyy)
    1 abc 1/1/2007
    1 def 2/1/2007
    2 ghi 1/1/2007
    2 --- 3/1/2007 (No value in col2)
    3 jkl 1/1/2007
    3 mno 4/1/2007
    I would like the output as follows:
    col1, col2,col3
    1 abc 2/1/2007
    2 3/1/2007
    3 mno 4/1/2007
    (ie with most recent update_dates)
    How to implement this in SQL?

    Double post.

  • Selcting records with most recent date

    Hello Friends
    I am new to this group.
    I am having a set of records as follows in a table
    col1,col2, col3(dd/mm/yyyy)
    1 abc 1/1/2007
    1 def 2/1/2007
    2 ghi 1/1/2007
    2 --- 3/1/2007 (No value in col2)
    3 jkl 1/1/2007
    3 mno 4/1/2007
    I would like the output as follows:
    col1, col2,col3
    1 abc 2/1/2007
    2 3/1/2007
    3 mno 4/1/2007
    (ie with most recent update_dates)
    How to implement this in SQL?

    or:
    SQL> create table t
      2  as
      3  select 1 col1, 'abc' col2, date '2007-01-01' col3 from dual union all
      4  select 1, 'def', date '2007-01-02' from dual union all
      5  select 2, 'ghi', date '2007-01-01' from dual union all
      6  select 2, null,  date '2007-01-03' from dual union all
      7  select 3, 'jkl', date '2007-01-01' from dual union all
      8  select 3, 'mno', date '2007-01-04' from dual
      9  /
    Tabel is aangemaakt.
    SQL> set autotrace on explain
    SQL> select col1, col2, col3
      2    from (select col1, col2, col3, row_number() over (partition by col1 order by col3 desc) rn
      3            from t)
      4   where rn = 1
      5  /
          COL1 COL COL3
             1 def 02-01-2007 00:00:00
             2     03-01-2007 00:00:00
             3 mno 04-01-2007 00:00:00
    3 rijen zijn geselecteerd.
    Uitvoeringspan
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   VIEW
       2    1     WINDOW (SORT PUSHED RANK)
       3    2       TABLE ACCESS (FULL) OF 'T' (TABLE)
    SQL> select col1
      2       , max(col2) keep (dense_rank first order by col3 desc) col2
      3       , max(col3) col3
      4    from t
      5   group by col1
      6  /
          COL1 COL COL3
             1 def 02-01-2007 00:00:00
             2     03-01-2007 00:00:00
             3 mno 04-01-2007 00:00:00
    3 rijen zijn geselecteerd.
    Uitvoeringspan
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   SORT (GROUP BY)
       2    1     TABLE ACCESS (FULL) OF 'T' (TABLE)Regards,
    Rob.

  • Choosing most recent records from multiple tables?

    Let's say that you have two tables; one contains news
    articles with the fields TITLE, ARTICLE, and a timestamp DATE and
    the other contains different news articles with the fields TITLE,
    DESCRIPTION, and a timestamp DATEPOSTED.
    How would you go about selecting the (let's say) five most
    recent articles with the corresponding fields? I'm relatively new
    to CF but even the experienced guy in our office can't figure it
    out. The following code is what we were working with -- which
    doesn't quite work the way it should anyway -- but I'm thinking
    there
    must be an easier (or at least less convoluted) way.

    Thank you so much! Azadi hit the nail on the head; I hadn't
    known the terms to look for so Google hadn't been any help, but
    UNION was just the trick for this MySQL query. I had to add a field
    to each table in order to tell the link which page to go to since
    there's a different one depending on which table the record came
    from, but here's the code that works (just in case anyone else does
    a search for this problem):

Maybe you are looking for

  • Keeping multiple domain.sites on the same computer

    Based on reading the help info, it seemed that if I had several domain.sites in DIFFERENT folders, I could open them separately and thus keep several different sites on the same computer (which I want to do to keep my student's work). However this do

  • Pages that load in all other browsers do not load in Safari

    Our Web application uses HTTPS and a Thawte-issued 256-bit AES SSL certificate. In IE, Firefox, and Chrome, the pages of our Web application load absolutely fine. In Safari 4.0.5, the pages do not load in the browser. When looking at the source for t

  • Metadata special characters problem

    You would be forgiven for thinking it easy to add a caption for each image to identify the photographer and her credentials. Metadata is there for that purpose and the IPTC "Author" field seems an obvious choice. However, most letters-after-your-name

  • Get the latest date record in Query

    Hi, Expert: Please help on this: The requirement is to get the the latest date record in Query. For example: Data in provider: Plant          date            amount A01         2007/04/08      30 A01         2007/06/09      70 A01         2007/12/08 

  • Need result of expensive query

    Hi All , I need a a query which will give the result of most expensive query i.e. whihc is taking most of I/O /memory. Thanks