DIGIT-ARC read-only archive · snapshot: July 23, 2026

finding first query from a table through sql

4 posts · originally from https://geek.digit.in/community/threads/finding-first-query-from-a-table-through-sql.164559/

anky
anky Original post #1
Oct 11, 2012 at 2:18 PM
hi..
i want to find first record and last record of a specific column lets say 'name' so how to get it ?
pls its urgent..
Flash
Flash #2
Oct 11, 2012 at 2:38 PM
Its unclear. So you want to sort the records by column 'NAME' to get first and last record?
RCuber
RCuber #3
Oct 11, 2012 at 3:32 PM
in SQL there is no first and last record.. the data stored is not sorted.. you need to query and sort it yourself.

Code:
SELECT TOP 1 [NAME] FROM tblSample ORDER BY [Name] ASC  'Gets First record Name is ascending order
SELECT TOP 1 [NAME] FROM tblSample ORDER BY [Name] DESC  'Gets First record Name is descending order
anky
anky #4
Oct 11, 2012 at 9:50 PM
thank u friends i got my answer, btw i wanted to ask that....lets consider an example..
i have a table name emp(employee)
and its records for empid is lets say like this
231
223
221
332
443
331
235

so i wanted a query that shows the first record .i.e the record entered first.which in this case is 231.
and similarlt, the last record i.e 235 in this case.
anywayz ..thanks for ypur help. :)