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
 Sql server

Author  Topic 

rohitsamnotra
Starting Member

1 Post

Posted - 2013-05-10 : 23:24:34
how to find 50th lowest value in a table using sql query ,, please help me out ,Reply soon

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2013-05-11 : 00:04:17
[code]With cte AS (
SELECT someColumn, row_number() over (order by someColumn) ix
FROM YourTable
)
SELECT someColumn
FROM cte
WHERE ix = 50;[/code]
Go to Top of Page

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-05-11 : 11:15:59
Or you can try this:

[CODE]

SELECT column_name FROM table_name ORDER BY column_name OFFSET 49 ROWS FETCH NEXT 1 ROWS ONLY;

[/CODE]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-13 : 00:45:03
quote:
Originally posted by MuMu88

Or you can try this:

[CODE]

SELECT column_name FROM table_name ORDER BY column_name OFFSET 49 ROWS FETCH NEXT 1 ROWS ONLY;

[/CODE]


Works only from SQL 2012 onwards

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-13 : 00:46:55
[code]
SELECT someColumn
FROM Table t
WHERE 49 = (SELECT COUNT(*)
FROM table
WHERE someColumn > t.someColumn
)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -