?
Solved

HOw to find a last record

Posted on 2006-05-05
1
Medium Priority
?
239 Views
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
0
Comment
Question by:MohamedAiz
1 Comment
 
LVL 4

Accepted Solution

by:
ecc204 earned 2000 total points
ID: 16620266
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.

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

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
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…
Progress

840 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