Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL -> Select second lowest value

Tags:

sql

php

mysql

I'm currently using min() to find the lowest value within MYSQL database.

How could i find the second lowest value?

'select Date, Horse, ParentID, min(odds2) 
from horsesrp 
where odds2 < 3.1 and odds2 > 1.9 
and Date = "'.$id.'" 
AND Track IN ("Kempton (AW)","Wolverhampton (AW)") 
group by ParentID order by ParentID'

please note i still need to order by ParentID as i want to get the second lowest odds2 per parentid

so my database look like:

Racetime Odds

13:05     2
13:05     2.4
13:05     3
13:05     5
13:30     3
13:30     5
13:30     9
13:30     13.5
14:00     1.14
14:00     1.19
14:00     2
14:00     4

i want to find the second lowest value for each time but it must be between 1 and 2.9

Racetime Odds

13:05     2.4
14:00     1.19

so the output for the above would be

Thanks

Emma

like image 358
emma perkins Avatar asked Dec 01 '22 15:12

emma perkins


1 Answers

SELECT * FROM table_name ORDER BY id ASC LIMIT 1, 1 
like image 148
Vamshi .goli Avatar answered Dec 07 '22 23:12

Vamshi .goli