how to select top 3rd record from a column in sql
A:
with tempTable(column1)
as (
SELECT top(3) column1
FROM table1
ORDER BY column1DESC
) select top(1)column1 from tempTable
or
need to take first 3 records use
SELECT top(3) column1
FROM table1
ORDER BY column1DESC
anishmarokey
2010-09-28 05:28:20
I've never seem the form clause before! Is that new for SQL Server 2005? :-)
codingguy3000
2010-09-28 13:43:33
Let he who has never tried to use the form clause cast the first negative comment!
codingguy3000
2010-09-28 13:44:17
it will not return 3rd record , it will return first 3 rows.
Avadhesh
2010-09-29 08:35:17
A:
For top 3 records it's simple:
SELECT TOP 3 <column-name> FROM <table>
For the third record in a result set, try this page How do I get the nth row in a SQL Server table?
Zabba
2010-09-28 05:34:05
A:
To get the third row from the top.
;with cte as
(
select *,
row_number() over (order by number) as rn
from master.dbo.spt_values
)
select *
from cte
where rn=3
To get the top third
select top (100.0/3) percent *
from master.dbo.spt_values
order by number
Martin Smith
2010-09-28 07:29:35
A:
You can use below query
SELECT *
FROM(
SELECT ROW_NUMBER() OVER (ORDER BY [OrderBYColumn]) AS SrNo,
<Column1,Column2,Column3 ....>
FROM
TableName
) AS TableAlias
WHERE
SrNo=3
Also for from and to range you can use
SELECT *
FROM(
SELECT ROW_NUMBER() OVER (ORDER BY [OrderBYColumn]) AS SrNo,
<Column1,Column2,Column3 ....>
FROM
TableName
) AS TableAlias
WHERE
SrNo between 3 and 5
Aamod Thakur
2010-09-28 09:35:22
A:
Select Top 1 col_name
From (Select Top 3 col_name from tablename order by col_name desc)
Avadhesh
2010-09-28 13:03:15