Jump to content

Selecting the top row


max_w1

Recommended Posts

hi i am trying to use a query like this

SELECT *

FROM `fares`

WHERE `KMS` >=201

LIMIT 0 , 30

 

which pops up a databse list of 30 rows which looks something like the one below

KMS SL_AD SL_CH

205 122         120

210 124  120

215 125  120

220 127  121

225 128  122

 

all i want to do is somehow sort and get only the first row(205  122 120) in my php program/

 

Thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/237875-selecting-the-top-row/
Share on other sites

all i want to do is somehow sort

Sort by what?

 

get only the first row

If you're wanting to get the first record that is closet to KMS 201 Then just use LIMIT 1 rather than LIMIT 0, 30

$query = 'SELECT * FROM `fares`WHERE `KMS` >=201 LIMIT 1';
$result = mysql_query($query);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.