0

I used MAX function.

How to get the second highest maths mark from the database.

e.g: (maths : 96 , 88 , 55);

SELECT MAX(maths) FROM mark;

how do I get 88 from SQL query?

Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28
R.Surya
  • 184
  • 12

7 Answers7

3
SELECT MAX( column ) FROM table WHERE column < ( SELECT MAX( column ) FROM table )
SNS
  • 485
  • 6
  • 20
2

If you want the second highest mark, you would use limit/offset:

SELECT DISTINCT maths
FROM mark
ORDER BY maths DESC
LIMIT 1, 1;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
2

You could use a subquery to get the overall maximum and then get the maximum of those values less the overall maximum.

SELECT max(maths)
       FROM mark
       WHERE math < (SELECT max(maths)
                            FROM mark);
sticky bit
  • 36,626
  • 12
  • 31
  • 42
1

select maths from mark order by maths desc limit 1 offset 1

Ankur Goel
  • 311
  • 1
  • 11
1

SELECT MAX( maths ) FROM mark WHERE maths < ( SELECT MAX( maths ) FROM mark )

Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28
0

Try this query

 SELECT MAX(maths) FROM mark WHERE maths NOT IN ( SELECT Max(maths) FROM mark);
Mik_ko
  • 134
  • 2
  • 9
0

The below code will help you.

SELECT DISTINCT mark
FROM testing
ORDER BY mark DESC
LIMIT 1, 1

And I just attached my table screen for your reference.

enter image description here

Ramya
  • 199
  • 10