How to find the last records of the table in adventure work db

hi all,
i want to find out " how to receive a last records of the table (eg:  person.emailaddress ) in sql 2008 and 2005"
Thanks

If you are looking for the latest record( the one which got inserted/modified last) then use this query
select top 1 * from person.emailaddress
Order by ModifiedDate desc
Satheesh
My Blog |
How to ask questions in technical forum

Similar Messages

  • Read the last record in the database table..

    Hi..
    I am new to ABAP. So i have one condition to read the address number field in the last record from database table by using the person number where clause field.
    But the person number is same for some the records.
    So can any tell me the logic for to read the addressnumber field in the last record of selected records from database where personnumber is equal to some thing.
    Please help me..
    Thanks
    venki

    Hi Venkat ,
    u mean to say
    person number  addressnumber
    aa1            0000000000001
    aa1            0000000000002
    aa1            0000000000003
    aa1            0000000000004
    aa2            0000000000021
    aa3            0000000000110
    if i have to read the addressnumber 00000000000004
    of the person number aa1
    u can go like
    data v_address number like addressnumber.
    sort itab by personnumber addressnumber
    loop at itab .
    at end of personnumber.
    move addressnumber to v_addressnumber ..
    endat.
    endloop.
    so using control break statements i can fetch the last record of my person number if at all the same person number is having more than one address number ..
    hope this helps,
    Regards,
    Vijay
    Message was edited by: Vijay

  • How to get the last record from the database

    I am using MS Access database and Swings as GUI. I want to get the last record of a particular column from the table and store it as a varaible.

    Hi
    To get Last record of resultset, you have pass some parameter in constructor of CreateStatement.In such case Resultset should be scrollable and Readonly
    Example
    objStatement=objCon.createStatement ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    mwwResultSet=cwwStatement.executeQuery(mwwSqlQuery);
    while(mwwResultSet.next())
    if(mwwResultSet.isLast())
    //Fetch the required column record.
    String abc=mwwResultSet.getString(1);
    I think this will work. Try it.
    bye

  • Getting the last record from the internal table

    When we use a READ statement it always picks up the first record which fulfill its condition but in my case I want to pick up the last record that fulfills it condition
    I have a internal table like
    id     type
    N1      A
    N1      T
    N1      A
    N1      6 ----> LAST RECORD
    my code is
    read table itab wIth key id = netobjid.
    for eg if netobjid = N1 , then I want to read the last record that corresponds to N1 ie ID N1 TYPE - 6...
    How to do that?

    HI
    actually i have done same requirement like this ...
    Take  one count variable into your internal table ..you pass the number of records into cont variable for every time  u enter the loop .
    Sort the internal table with count variable descending . ( AS we cant sort the internal table with sy-tabix)
    Then use read statement with sy-index = 1 .
    USe below logic ,............
    data  :  count  type i value '0'.
    LOOP at int .
    count = count + 1 .
    endloop.
    sort int count descending .
    read int  with  index = 1 .

  • How to get the last record??

    Hi, I now have to get only the last record from one table
    from MS Access.
    I was looking for the useful method from API, however,
    I cannot get it.
    How to get only the last record from one table ???
    Please help, thanks.

    In RDBMS, row order is really not relavent by iteself. Meaning there is no such thing as 'last record' unless it's in the context of a column (e.g. timeStamp).
    Of course, rows are inserted and stored in some natural order, but you cannot assume they'll come back the same way in a 'Select *' as they were entered.
    So, if you mean last row as in last inserted row, I would add a timestamp field that's set at insert, or use a autonumber column. Either way, have a column that will always contain the highest number or newest timestamp, and then you can build your where clause from that.
    For instance, in Access, I have an autonumbered field called 'fred', with other columns. If I want the last record, I simply use the following:
    select * from atable where fred in (SELECT max(fred) AS Max FROM atable);
    the 'where in' clause will filter to only those records in the subsequent select statment, which of course is only one, the max of the column fred.
    bRi

  • How to get to the last record of an APEX report automatically?

    In Oracle Forms there is a "lastrec" command which can be placed after a call to a multi-row form.  The records called have the last record at the bottom of the page.  For example, if there are 100 records and there are 10 rows on the form, record numbers 91 through 100 would be showing.  Can this be done in APEX?  I have a user who wants it this way.  I set the report page up to be ordered descending, which gives her last record at the top of the page, but this is not acceptable to her.  She wants to see the last record, but she wants it at the bottom of the page. 

    Hi,
    Try this query, it should order your data as you want and the report pagination is not broken!
    The number of row displayed must be the same as the divide by value (ie. 10)
    select your_id
    from your_table
    order by trunc ((DENSE_RANK() OVER (  ORDER BY your_id desc) -1) /10)
        , DENSE_RANK() OVER (  ORDER BY your_id desc) desc;
    Page 1 displays 91 to 100
    Page 2 displays 81 to 90
    Also if your data set have 87 rows, Page 1 will display 78 to 87 (ie. the 10 last rows).
    If you want more details regarding the sorting you can have a look on this query:
    select your_id
         , trunc ((DENSE_RANK() OVER (  ORDER BY your_id desc) -1) /10)
         , DENSE_RANK() OVER (  ORDER BY your_id desc)
    from your_table
    order by 2, 3 desc;

  • How to get the only the last raw of the table

    Hello All,
    While fetching a table into internal table, how to get only the last record of the table.?
    Thanks and Regards, Pradeep

    I hope following code will solve your problem.
    DATA : it_bseg TYPE TABLE OF bseg,
           x_bseg TYPE bseg,
           v_index TYPE i.
    SELECT COUNT(*)
      FROM bseg
      INTO v_index.
    SELECT *
      FROM bseg
      INTO TABLE it_bseg.
    READ TABLE it_bseg INTO x_bseg INDEX V_INDEX.
    First SELECT will give you the number of rows in a table in v_index. Second SELECT will fetch all table data and then READ will give you the last record of the table in a structure x_bseg.
    Reward points if the answer is helpful.

  • How to only read the last line in the text file by using BufferedReader ?

    Dear all,
    Hello, I am new to Java. Do anybody know how to read the last line (this is the last record) in the text file.The method I am now using is reading from the first line until I reach the last line in the text file. Thank you!!
    BufferedReader br = new BufferedReader(new FileReader("c:\\sdk1.4.1\\bin\\dbExport.txt"));
    DataInputStream in = new DataInputStream(new FileInputStream("c:\\sdk1.4.1\\bin\\dbExport.txt"));
    String input;
    String firstinput;
    String secondinput;
    int count=90;
    int year=1955;
    while ((input = br.readLine()) != null) {
    firstinput = input.substring(0, 10);
    secondinput = input.substring(10);
    String insertStore1 = ("INSERT INTO AUTHORS " +
    "VALUES ('" + count + "', '" + firstinput + "', '" + secondinput + "', 1955)");
    System.out.println(insertStore1);
    int result = stmt.executeUpdate(insertStore1);

    I suppose you could use a java.io.RandomAccessFile.

  • Need to fetch the last record/row from a table

    Hi,
    I have a requirement like fetching the closing balance of the last record of the table and inserting the same into the opening balance of the immediatetly created next record.
    In simple words, I need to fetch a value from the last row of the record.
    For example, I use the below query,
    select rownum, empno, ename from emp
    where rownum = (select count(rownum) from emp);
    But, the above query does not return any of the record.
    Hence, need help on this.
    Regards,
    Shivakumar A
    Edited by: shiva on Mar 27, 2011 10:14 PM

    Rows in a table are inherently unordered. In order to introduce the concept of "first" and "last", you would need to specify how to order the rows which would require that there was one or more columns in the table that you could order by in order to determine the "last" record.
    In your closing balance example, if we assume that there is something like a BALANCE_DATE column,
    SELECT account_number, balance_amount, balance_date
      FROM (
        SELECT account_number,
               balance_amount,
               balance_date,
               rank() over (partition by account_number order by balance_date desc) rnk
          FROM table_of_balances )
    WHERE rnk = 1Justin

  • Compare 2 data sets and display the last record

    I have one record in first table and 2 records in second table.
    Ex:Table 1:
    A     100     200   0
    B     200     300   0
    Table 2:
    A      0        0     100
    A      0        0     500
    B      0        0     700
    In one final template I want to display like below with only 2 records like below.
    A      100    200    500
    B      200    300    700
    Anybody suggest me how to pick only last record if the count is greater than 1 in second table.

    not sure what are you trying to do
    if you want to join two table then sql is more useful IMHO
    Anybody suggest me how to pick only last record if the count is greater than 1 in second table.
    you can get last record by last() function
    <?for-each:SOMETAGorGROUP[position()=last()]?>

  • Moving the last record to 1st position

    Hi,
    I have 200 records in my internal table.I want to move the last record(200 position) to 1st position(i.e Index1). How to do it?

    Hi
    U can try something like this
    DATA: BEGIN OF ITAB OCCURS 0,
            FIELD(1) TYPE C,
          END   OF ITAB.
    DO 9 TIMES.
      MOVE SY-INDEX TO ITAB-FIELD.
      APPEND ITAB.
    ENDDO.
    * Check table
    DESCRIBE TABLE ITAB LINES SY-TABIX.
    * Read last record
    READ TABLE ITAB INDEX SY-TABIX.
    * Delete last record
    DELETE ITAB     INDEX SY-TABIX.
    * Append the last record to the top
    INSERT ITAB     INTO ITAB INDEX 1.
    LOOP AT ITAB.
      WRITE: / ITAB.
    ENDLOOP.
    Max

  • Not enough space to print the last record on each page

    Hello,
    My report looks like a simple list table, with the first row as the column header, followed by rows of records.
    The fields are placed on the Detail section and they're set with "Can Grow" property. That means, records may have different row height, some may take 1 row per record, some may take 3 rows per record, depending on the data length. I use some vertical lines on the Detail section as the column seperators, and a horizontal line as the record seperator.
    I've a Page Footer to show the page number and print date.
    My problem is:
    When the space of the last record on the current page isn't big enough, the record will be printed automatically on the second page, which is fine. But the vertical seperation lines are still displayed even though the details are printed on the second page. I got some "empty rows with vertical seperation lines" or I'd say an open-end table at the end of some pages then.
    Is there a way to avoid this?
    Your help is much appreciated. Thank you.
    Agnes

    You could draw an outline box from page header to page footer, then your internal lines would run from page header to page footer
    so if the document extends to 2 pages, the page footer will print on the 1st page and therefore the bottom line of the box
    only problem now would be that on the 2nd page the box will extend to the bottom of that page also, even if there is only 1 record

  • Selecting the last record from a database table

    In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key.  In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first.  I know I can use an internal table to sort the records first and then retrieve the right value.   But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step?  Thanks!

    hi,
    tables:mara.
        data: begin of it_mara occurs 0,
                matnr like mara-matnr,
                meins like mara-meins,
                mtart like mara-mtart,
                end of it_mara.
    select-options:s_matnr for mara-matnr.
    select matnr
              meins
              mtart
    from mara
    into table it_mara
    where matnr in s_matnr.
    if not it_mara[] is initial.
    sort it_mara by matnr descending.
    read table it_mara index 1.
    endif.
    then you get the last record of the select statement.
    reward points if useful,
    venkat.

  • To find the last record in cursor

    hi
    DECLARE
    vCounter NUMBER;
    -- Other variables...
    BEGIN
    vCounter:=0;
    FOR .. IN cursor LOOP
    IF vCounter=0 THEN
    -- Here open file...
    -- Here write one time data...
    END IF;
    -- Here write cursor data...
    vCounter:=1;
    END LOOP;
    END;
    hi all i am using above code to find the first record.
    if vCounter =1 means its first record.
    Now my question is how to find out the 'n'th record(last record).
    please help me.
    Thanks..

    user13329002 wrote:
    hi
    DECLARE
    vCounter NUMBER;
    -- Other variables...
    BEGIN
    vCounter:=0;
    FOR .. IN cursor LOOP
    IF vCounter=0 THEN
    -- Here open file...
    -- Here write one time data...
    END IF;
    -- Here write cursor data...
    vCounter:=1;
    END LOOP;
    END;
    hi all i am using above code to find the first record.
    if vCounter =1 means its first record.
    Now my question is how to find out the 'n'th record(last record).
    please help me.
    Thanks..create a record type variable to store last record;
    assign the fetch data to that variable
    and when u exit from the loop ,the variable will have the last records value
    since you are using cursor for loop , it will Implicitly open, fetch, exit, and close occur to cursor.
    eg:-
    DECLARE
    type cur_type is  record of yourcursorname%type;
    rec_cur_type cur_type;
    vCounter NUMBER;
    -- Other variables...
    BEGIN
    vCounter:=0;
    FOR .. IN cursor LOOP
    IF vCounter=0 THEN
    -- Here open file...
    -- Here write one time data...
    END IF;
    -- Here write cursor data...
    assign your fetched record from cursor to rec_cur_type
    vCounter:=1;
    END LOOP;
    END;

  • How to restrict the last record and not moving to next reocrd

    1) how to restrict the last record and not moving to next reocrd.
    2) Also for the F6 key(for new record).

    When you are on the last record, next-record will create a new one, so that my question is do you want to forbid new record creation.
    Francois

Maybe you are looking for