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
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.