finding first query from a table through sql

anky

Youngling
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

Lost in speed
Its unclear. So you want to sort the records by column 'NAME' to get first and last record?
 

RCuber

The Mighty Unkel!!!
Staff member
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
 
OP
anky

anky

Youngling
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. :)
 
Top Bottom