Select the last 10 records in a table

Oracle9i. I am trying to select the last 10 numbers in a table with this command series
select serial from tab_42 where employeecode='00001'  and rownum<=10 order by serial desc;
but it's not not selecting the most recent serial number 10. How to do?

The rownum clause is applied before the order by clause, one must use a subquery...

select * from (select serial from tab_42 where employeecode='00001' order by serial desc) where rownum<=10;

Tags: Database

Similar Questions

  • How to select the last 3 records in a table?

    I have a table named HRM_ATTENDANCE
    as follows
    Name         Type         Nullable Default Comments 
    ------------ ------------ -------- ------- -------- 
    LEAVEDATE    DATE                                   
    EMPLOYEECODE VARCHAR2(8)                            
    LEAVETYPE    VARCHAR2(4)                            
    APPROVEDBY   VARCHAR2(8)  Y                         
    FEEDBY       VARCHAR2(8)  Y                         
    FEEDTIME     DATE         Y                         
    REMARKS      VARCHAR2(50) Y 
    the table contains the record of leave of employees as follows
    LEAVEDATE   EMPLOYEECODE LEAVETYPE APPROVEDBY FEEDBY   FEEDTIME    REMARKS
    ----------- ------------ --------- ---------- -------- ----------- --------------------------------------------------
    6/1/2013    00001        CL  
    6/3/2013    00001        EL                                         
    6/5/2013    00001        CPL    
    6/7/2013    00001        SL 
    6/9/2013    00001        CL                                        
    I want to select the last 3 leaves (records) to employeecode "00001" so I don't know the what are the dates of the leave. in easy words I want to choose the folder where leavedate > = 5 June 2013 ", but I don't know any dates."

    Select * from HRM_ATTENDANCE where rownum<=3 order="" by="" leavedate="">

  • How to select the last 20 transactions in a table

    Hi guys,.
    I have a table named INOUT with following columns

    EMPLOYEECODE VARCHAR2
    DATE OF THE RESPONDENT


    each day employees now their me 'in '. then entered came and came in this table. If we want to select the last 20 EMPLOYEECODE in this table that make their selves 'in '. How to choose that? just 20 last employees who traded. Help, please

    Hello

    This is called a Query Top - N , you want to choose elements of N (N = 20, in this case) from the top of a sorted list.
    Here's a way to do it:

    WITH     got_r_num     AS
    (
         SELECT       emloyeecode
         ,       MAX (intime)     AS latest_intime     -- If wanted
         ,       RANK () OVER (ORDER BY  MAX (intime)  DESC)
                        AS r_num
         FROM       inout
         GROUP BY  employeecode
    )
    SELECT     employeecode
    ,     latest_intime          -- If wanted
    ,     r_num               -- If wanted
    FROM     got_r_num
    WHERE     r_num     <= 20
    ;
    

    That actaully could take more than 20 people: If there be a tie, it includes any person who is entitled to be in the top 20. If you want exactly 20 people, then add the columns of tiebreaker to analytical or use ROW_NUMBER instead of RANK ORDER BY clause.

  • Need to retrieve the last line/record in a table

    Hello

    I have a requirement like getting the ending balance of the last record in the table and the same insertion in the opening balance of the immediatetly created the next record.

    In simple terms, I need to extract a value from the last line of the recording.

    For example, I use the query below

    Select rownum emp, empno, ename
    where rownum = (select count (rownum) from emp);

    But, the above query does not return all of the recording.

    Therefore, need help on this.

    Kind regards
    Shivakumar has

    Published by: shiva March 27, 2011 22:14

    Hello
    Strictly speaking there is no such LAST or FIRST folder until that order you them.
    But check the following:

    SELECT * FROM emp MINUS
    SELECT * FROM emp WHERE rownum<=(SELECT count(empno)-1 FROM emp);
    

    Kind regards
    Lakshmi.

  • Select the last 7 days

    How to select the last 7 days of my table, I use the query, but it is the calculation according to sysdate
    It is the data of my talble
    DP_DATE
    ---------
    03-APR-10
    21-APR-10
    22-APR-10
    23-APR-10
    26-APR-10
    27-APR-10
    28-APR-10
    29-APR-10
    30-APR-10
    03-MAY-10
    04-MAY-10
    
    11 rows selected.
      select distinct dp_date
      from dailyprice
      where trunc(dp_date) between trunc(sysdate-7) and trunc(sysdate)
    
    this query is returning 
    DP_DATE
    ---------
    29-APR-10
    30-APR-10
    03-MAY-10
    04-MAY-10
    I want to choose last 7 days
    APRIL 26, 10
    APRIL 27, 10
    28 APRIL 10
    APRIL 29, 10
    30 APRIL 10
    MAY 3, 10
    4 MAY 10

    kindly Guide

    concerning

    Hello

    Use DENSE_RANK() rather than ROW_NUMBER().

    with mytable
    as
    (
    select 'abcFund' FND , to_date('09-MAY-10','dd-mon-rr') dp_date, 10 price from dual union all
    select 'dddFund', to_date('09-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('09-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('09-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('09-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('08-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('07-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('07-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('07-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('05-MAY-10','dd-mon-rr'), 11 from dual union all
    select 'dddFund', to_date('05-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('05-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('04-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('04-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('03-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('03-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'edfFund', to_date('03-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'eeeFund', to_date('03-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'dddFund', to_date('01-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('01-MAY-10','dd-mon-rr'), 12 from dual union all
    select 'abcFund', to_date('30-APR-10','dd-mon-rr'), 11 from dual
    )
    select dp_date
          from ( select dp_date
                      , dense_rank() over (order by dp_date desc) rn
                   from mytable
               )
         where rn <= 7;
    

    Courtesy: Rob SQL
    * 009 *.

    Published by: 009 on May 6, 2010 05:01

  • Select the last disk in the history table

    How to select the last record in a history table? the example data is
    < p >
    Product EffectiveDate

    prod1 01/01/1980

    prod1 01/01/1990

    prod1 01/01/2000

    prod2 02/02/1980

    prod2 02/02/2000
    < /p >
    < p >


    The expected result is



    Product EffectiveDate

    prod1 01/01/2000

    prod2 02/02/2000
    < /p >

    Assuming that there is a single line with max (effectivedate) for a given product

    SELECT product, attrib1, attrib2, ... , max_effective_date
      FROM (SELECT product,
                   attrib1,
                   attrib2,
                   ... ,
                   effectivedate,
                   max( effectivedate ) over (partition by product) max_effective_date
              FROM history_table)
     WHERE effectivedate = max_effectivedate
    

    should work.

    Justin

    Published by: Justin cave on October 30, 2008 18:32

    Formatting changes

  • Select the last record of each month

    Hello

    to select the last docnumber and qty of every month

    Structure

    Name Null?    Type

    ------------------------------- -------- ----

    PRODUCTCODE NUMBER

    NUMBER NUMBER

    DATE OF PLANFORMONTH

    NUMBER OF CLEXPECTEDQTY

    NUMBER OF CLCONFIRMQTY

    NUMBER OF CLFGBUFFERQTY

    NUMBER OF CLTOTPRINTBUFFER

    in this select query if I take the sum he required all records where, as I want the last record of each month

    SELECT productcode docnumber MAX (Number), planformonth, SUM (clexpectedqty) clexpectedqty (planformonth) MAX.

    SUM (clconfirmqty) clconfirmqty, SUM (clfgbufferqty) clfgbufferqty, cltotprintbuffer OF FGSALESPLAN of the SUM (cltotprintbuffer)

    GROUP BY productcode, (planformonth)

    Sandy

    Hello

    Thanks its working now the code is written as below:

    SELECT * FROM

    (SELECT

    e.*,

    ROW_NUMBER() OVER (partition by PRODUCTCODE by DOCNUMBER DESC order) r

    Of

    E FGSALESPLAN)

    WHERE r = 1 AND

    entryvalid = 'Y '.

    order by Number

    Sandy

  • By selecting the last row of the table

    I'm trying to select the last row in a table. The tables will have a different number of lines, so I can't select based on a line number. I tried to use the location options, but get an error that "the object is not a function". Not sure what the problem is.

    table = app.selection[0];
    if (table.hasOwnProperty("baseline")) table = table.parent;
    if (table instanceof Cell) table = table.parent;
    if (table instanceof Column) table = table.parent;
    if (table instanceof Row) table = table.parent;
    if (table instanceof Table)
    
    {
                table.rows(LocationOptions.AT_END).cells.texts.everyItem().fontStyle = "regular";
     }
    

    You can use the placement options for this?

    Hello

    table. Rows being a collection of object using the index-[1] is a proper way

    but cells.texts generates an error. Change it to:

    table.rows[-1].cells.everyItem().texts.everyItem().appliedCharacterStyle = "myriad regular";
    

    Jarek

  • I need a query that selects the amount of records for each day of a table.

    I need a query that selects the amount of records for each day of a table.
    For example, the result would be:

    1 14 date
    Date 2-3

    etc.

    Any ideas?

    Sort:

    SELECT count ([IDCommentaire]), convert (varchar, dateAdded, 112)

    OF COMMENTSgroup by convert (varchar, dateAdded, 112)

  • Select the last 50 closed records

    The research of a statement select simple sql which selects the latest 50 records closed in the database.

    I found some help out there who have an example like:

    SELECT RecordID, closed_date
    (SELECT RecordID, closed_date, RANK() over (ORDER BY closed_Date DESC) date_rank
    FROM table1)
    WHERE the date_rank < = 50;

    Only problem is, this is to select something like 4000 recordings, and many of them are not yet closed.

    I think that you need to retrieve the records that are only closed in the first place.

    Try this,

    SELECT RecordID, closed_date
      FROM (SELECT RecordID,
                   closed_date,
                   ROW_NUMBER () OVER (ORDER BY closed_Date DESC) rn
              FROM table1
             WHERE closed_date < SYSDATE)  --Notice this.
     WHERE rn <= 50;
    

    G.

  • How to identify the last instance of a dynamic table row

    Hi all

    I'm trying to figure out how to create an action for my form in Livecycle Designer ES2, which will affect the last instance of a dynamic table row. I have a table with a repeatable row where the user will enter information about a part purchased and I have buttons that allow the user to add and remove the lines. I need to create a line extra addition button which will add a new instance of the repeatable table line (this is not a problem) and disable and change the background color of the first cell in the row added. The problem I have is how to have an action that affects the last instance of a line.

    If anyone knows how to do this in Javascript, I would appreciate some advice/help.

    Hello

    I think that it is beyond providing an action. You will have a need to write JavaScript directly.  When you call the addInstance method it returns the new line, if you can do something like;

    var line = Table1._Row1.addInstance ();

    line. TextField1.border.fill.color.value = "255,0,0";

    line. TextField1.access = 'protected ';

    To find the last line and do the same thing, you can do something like;

    var line = Table1.resolveNode ("Row1 [" + (Table1._Row1.count - 1) + "" "]" ");

    line. TextField1.border.fill.color.value = "255,0,0";

    line. TextField1.access = 'protected ';

    Concerning

    Bruce

  • Cannot select the last picture

    Hello

    I have 75 frames in an animation. I have about 6 layers.

    I'm putting a stop on the last image statement.

    Whenever I open the Actions window it says even if image 1

    the playhead is positioned on the last image.

    How to place a stop comand on the last image and which layer

    should I select?

    Thank you

    Jim

    After having selected the last image, right-click on it and select Insert image.  You should now be able to add your stop() command in the last picture.

  • Select the last character of a string

    Hello
    I want to select the last character of a string address. "For example, as a result of select ' 165 John Ave W '-'W '. I tried to use the RIGHT but it does not work. I am using sqlplus.

    SELECT RIGHT(ADDRESS,1) FROM addresses;
    ORA-00904: "RIGHT": invalid identifier

    I can't find that any select statement to get the result I want. Ideas?

    Thank you!

    You want: SUBSTR (, - 1).

  • Select the last value for each day of the table

    Hello!

    I have a table that contains several measures for each day. I need two queries on this table, and I'm not sure how to write them.

    The table stores the rows (sample data)
    *DateCol1                 Value       Database*
    27.09.2009 12:00:00       100           DB1
    27.09.2009 20:00:00       150           DB1
    27.09.2009 12:00:00       1000          DB2
    27.09.2009 20:00:00       1100          DB2
    28.09.2009 12:00:00       200           DB1
    28.09.2009 20:00:00       220           DB1
    28.09.2009 12:00:00       1500          DB2
    28.09.2009 20:00:00       2000          DB2
    Explanation of the data in the sample table:
    We measure the size of the data files belonging to each database to one or more times a day. The value column indicates the size of the files of database for each database at some point (date in DateCol1 European model).


    What I need:
    Query 1:
    The query must return to the last action for each day and the database. Like this:
    *DateCol1       Value      Database*
    27.09.2009        150          DB1
    27.09.2009       1100          DB2
    28.09.2009        220          DB1
    28.09.2009       2000          DB2
    Query 2:
    The query should return the average measurement for each day and the database. Like this:
    *DateCol1       Value      Database*
    27.09.2009       125          DB1
    27.09.2009      1050          DB2
    28.09.2009       210          DB1
    28.09.2009      1750          DB2
    Could someone please help me to write these two queries?

    Please let me know if you need further information.

    Published by: user7066552 on September 29, 2009 10:17

    Published by: user7066552 on September 29, 2009 10:17

    Why two queries when it suffice ;)

    SQL> select dt
      2       , db
      3       , val
      4       , avg_val
      5    from (
      6  select dt
      7       , val
      8       , db
      9       , row_number () over (partition by db, trunc (dt)
     10                                 order by dt desc
     11                            ) rn
     12       , avg (val) over (partition by db, trunc (dt)) avg_val
     13    from test)
     14   where rn = 1
     15  order by dt
     16  /
    
    DT        DB           VAL    AVG_VAL
    --------- ----- ---------- ----------
    27-SEP-09 DB2         1100       1050
    27-SEP-09 DB1          150        125
    28-SEP-09 DB2         2000       1750
    28-SEP-09 DB1          220        210
    
  • If the record not found this particular date, then select the last recordings date.

    I have three columns
    Number DP_FND_CODE;
    Date of DP_DATE;
    Number DPPRICE;

    I want that if dp_uprice not found this particular date (: dd1) then
    Select maximum Dp_uprice that the date would be less then: dd1

    Example: -.
    I run query and :DD1 parameter = 18/10/2010
    
    SELECT dp_fnd_code, dp_date , dp_uprice dpprice 
    FROM dailyprice where dp_date = :dd1
    
    DP_FND_CODE DP_DATE                      DPPRICE
    ----------- ----------------------- ------------
              1 18/10/2010                  109.0344
              2 18/10/2010                   10.1045
              3 18/10/2010                  100.4010
              4 18/10/2010                  102.3276
              6 18/10/2010                   14.6958
              7 18/10/2010                   98.8300
              8 18/10/2010                  102.0900
    It will show that all the Archives: dd1 = 18/10/2010, you can see above the result of the query DP_FND 5 is missing.
    I want to if there is no DPRICE of that particular date (: DD1) then it shows the date of the last DPPRICE.
    Like this
    DP_FND_CODE DP_DATE                      DPPRICE
    ----------- ----------------------- ------------
              1 18/10/2010                  109.0344
              2 18/10/2010                   10.1045
              3 18/10/2010                  100.4010
              4 18/10/2010                  102.3276
              5 16/10/2010                  122.3276          
              6 18/10/2010                   14.6958
              7 18/10/2010                   98.8300
              8 18/10/2010                  102.0900
    so I used this query, but correct nicely.
    SELECT dp_fnd_code, dp_date, 
                 case when dp_uprice is null then(
               select max(dp_uprice) dpprice from dailyprice where dp_date < :dd1 group by dp_fnd_code,dp_date
               ) else dp_uprice  end dpprice 
      FROM dailyprice 
      where dp_date = :dd1
      order by dp_fnd_code
      
    Thanks in advance.
    SELECT dp_fnd_code,
           max(dp_date) keep (dense_rank last order by dp_date),
           max(dpprice) keep (dense_rank last order by dp_date)
      FROM dailyprice
      where dp_date <= :dd1
      group by dp_fnd_code
      order by dp_fnd_code;
    

Maybe you are looking for