Jump to content

Recommended Posts

Hi everyone,

 

I need to pull a record from my db, where data in 1 column is the highest?

 

So in my database, if i have....

 

ID        JOB NO        COMPANY        COLOUR

1          650              Ours                Red

2          700              Theres            Yellow

3          023              Ours                Orange

 

I need to pull the highest number from the JOB NO where the COMPANY value = 'Ours', so the echo'd value will be = 650

 

Is this possible?

Link to comment
https://forums.phpfreaks.com/topic/203077-highest-value-in-db/
Share on other sites

SELECT * FROM table_name WHERE COMPANY = 'Ours' ORDER BY JOB_NO DESC LIMIT 1

 

should work

 

EDIT: A little more specific :


$sql = "SELECT JOB_NO FROM table_name WHERE COMPANY = 'Ours' ORDER BY JOB_NO DESC LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

echo $row['JOB_NO'];

 

Link to comment
https://forums.phpfreaks.com/topic/203077-highest-value-in-db/#findComment-1064086
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.