Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select top statement ?

Author  Topic 

pamyral_279
Posting Yak Master

143 Posts

Posted - 2007-03-25 : 03:54:03
Hi everyone ,
My structure and data of my table store
Firstname LastName
A1------------A11
A2------------A22
A3------------A33
A4------------A44
....

I want to get each row by using "select top" statament.
Example :
select top 1 from mytable ==>I will get : A1 and A11
My problem :
How to get row which include : A2 and A22 by using "select top" !
How to get row which include : A3 and A32 by using "select top" !
and so on ...
Any one show me solutions ?
Thank you very much.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-25 : 04:25:54
You should always use TOP with ORDER BY

select top 1 * from mytable order by Firstname


"How to get row which include : A3 and A32 by using "select top" !"
You wanted to get the 3rd record ?

select top 1 *
from
(
select top 3 * from mytable order by Firstname
) a
order by Firstname desc



KH

Go to Top of Page
   

- Advertisement -