Find N’th largest details from a table using SQL.

Assume that I have a table called File Types, Which contain different set of Data. One of my requirement I need to select ‘N’ th largest Position of record using an sql statement.
For example I need to select 3rd largest file type id from the list.

FilyTypeId
Name
1
Art
2
Backers
3
Cover
4
Indicia
5
Layers
6
Logo
7
Premium
8
Test
9
Carting
10
Root
11
Backup
12
Back Sheet
13
Loose
14
Odd
15
Duplicate
16
Plain
 Solution:

SELECT MAX(fileTypeId) FROM filetypes WHERE fileTypeId IN
            (SELECT TOP 3 fileTypeId  FROM filetypes ORDER BY fileTypeId)
Out put: 3

No comments:

Post a Comment