HOw to find a last record

Posted on 2006-05-05
Last Modified: 2010-04-17
i have a SQL Table Name is "Sales" , i need to find out the last record of Selected Items for example

in my table the item Code "A1" is repeated at several times now i would like to find out the last record of "A1" how can i write a SQl Quary for that
Question by:MohamedAiz
    1 Comment
    LVL 4

    Accepted Solution

    Lets assume that you have a table with a primary key named ID.  ID is incremented every time you add a new row.  Also assume that you have a column named ItemCode which holds string values.  You are looking for the last record entered which has ItemCode equal to 'A1'.  Here is the SQL query string.


    First record would be

    SELECT TOP 1 * FROM Sales WHERE ItemCode='A1' ORDER BY ID;

    If you do not want only one record,  remove "TOP 1" from the statement.

    Good luck

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    wait notify demo infinite loop 3 66
    modThree challenge 4 49
    tenRun challenge 28 67
    zeroMAx challenge 20 66
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now