liamloveslearning Posted May 27, 2010 Share Posted May 27, 2010 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 More sharing options...
ixicoding Posted May 27, 2010 Share Posted May 27, 2010 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 More sharing options...
Zane Posted May 27, 2010 Share Posted May 27, 2010 Two ways... pick one SELECT MAX(JOB_NO) FROM tableName WHERE Company = "Ours" SELECT JOB_NO FROM tableName WHERE Company = "Ours" ORDER BY JOB_NO DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/203077-highest-value-in-db/#findComment-1064087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.