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,103
  • 3
  • 10
  • 27
R.Surya
  • 174
  • 11

7 Answers7

3
SELECT MAX( column ) FROM table WHERE column < ( SELECT MAX( column ) FROM table )
SNS
  • 457
  • 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,198,228
  • 53
  • 572
  • 709
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
  • 35,543
  • 12
  • 29
  • 39
1

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

Ankur Goel
  • 301
  • 1
  • 9
1

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

Sayed Mohd Ali
  • 2,103
  • 3
  • 10
  • 27
0

Try this query

 SELECT MAX(maths) FROM mark WHERE maths NOT IN ( SELECT Max(maths) FROM mark);
Mik_ko
  • 124
  • 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
  • 179
  • 10