Click here to Skip to main content
15,912,312 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi..i want nth row from a selected table with out using any column name.Can any one help..in sql server.
Posted
Updated 26-Jan-17 19:19pm

 
Share this answer
 
Use Column name in order by
SQL
SELECT * FROM
(
   SELECT empbirth.*, ROW_NUMBER() OVER (order by name) AS RowNum from empbirth
) sortly
WHERE RowNum =8

but if you do'nt want to use col name then you can try as
SQL
SELECT * FROM
(
   SELECT empbirth.*, ROW_NUMBER() OVER (order by (select top 1 column_name from information_schema.columns
 where table_name = 'empbirth')) AS RowNum from empbirth
) sortly
WHERE RowNum =8

Hope it solves your problem
 
Share this answer
 
Comments
hussy rao 31-Jan-12 2:32am    
Thank You..But this is working in latest versions of sql server2008 not in 2000,2005..thank you
uspatel 31-Jan-12 2:43am    
In sql server 2000 , there is no function ROW_NUMBER().
but you can search alternatives of ROW_NUMBER() on Google...
you can use
ROW_NUMBER()
and get nth row
 
Share this answer
 
v2
Comments
hussy rao 31-Jan-12 2:39am    
sorry sir im not getting the result..
Here n is the row number.
SELECT * FROM (
  SELECT
    ROW_NUMBER() OVER (ORDER BY key ASC) AS rownum,
    columns
  FROM tablename
) AS foo
WHERE rownum <= n


Hope,this helps.
 
Share this answer
 
v2
Comments
[no name] 27-Jan-17 7:12am    
The question was asked and answered FIVE years ago.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900