Jump to content

Highest value in DB


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

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.