Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to select maximum values in below table
day	count
0	18
4	66
5	6
6	322
7	18
8	15
9	30
10	155
11	3
13	4
14	5
15	1
16	4
17	2
18	1
20	4
21	1
23	2
24	1
25	9
26	1
27	1
28	1
30	3
31	1
32	1
35	3
36	1
40	1
44	1
45	5
50	4
52	1
55	8
56	1
60	2
65	1
70	1
75	1
80	1
90	1

here i want to take only one row that is highest in the table

how can take that
Posted
Updated 31-Mar-15 20:08pm
v2
Comments
Maciej Los 1-Apr-15 2:08am    
Highest count?
Member 11337367 1-Apr-15 2:21am    
yes
Maciej Los 1-Apr-15 2:22am    
See my answer.

1 solution

Try this:
SELECT  t2.day, t1.HighestCount
FROM (
    SELECT MAX(t1.count) AS HighestCount
    FROM TableName
)  AS t1 INNER JOIN TableName AS t2 ON t1.count = t2.count


or:
SQL
SELECT day, count
FROM (
    SELECT day, count, ROW_NUMBER() OVER(ORDER BY count DESC) RowNo
    FROM TableName
) AS t
WHERE t.RowNo = 1
 
Share this answer
 
v3

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