SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql server
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rohitsamnotra
Starting Member

India
1 Posts

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

russell
Pyro-ma-ni-yak

USA
5072 Posts

Posted - 05/11/2013 :  00:04:17  Show Profile  Visit russell's Homepage  Reply with Quote
With cte AS (
	SELECT 	someColumn, row_number() over (order by someColumn) ix
	FROM	YourTable
)
SELECT	someColumn
FROM	cte
WHERE	ix = 50;

Edited by - russell on 05/11/2013 00:05:12
Go to Top of Page

MuMu88
Aged Yak Warrior

547 Posts

Posted - 05/11/2013 :  11:15:59  Show Profile  Reply with Quote
Or you can try this:



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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 05/13/2013 :  00:45:03  Show Profile  Reply with Quote
quote:
Originally posted by MuMu88

Or you can try this:



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




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

India
52325 Posts

Posted - 05/13/2013 :  00:46:55  Show Profile  Reply with Quote

SELECT	someColumn
FROM	Table t
WHERE 49 = (SELECT COUNT(*)
            FROM table
            WHERE someColumn > t.someColumn
            )


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000