Jump to content

get row with higest value.


seany123

Recommended Posts

this is a php/mysql question.

 

basically i want to get the row with the highest value

 

value being episode_id

 

so something like

 

$query = mysql_query("SELECT * FROM table WHERE episode_id=highestvalue");

 

or i dont know something like that.

 

any help would be great!

 

thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/237011-get-row-with-higest-value/
Share on other sites

i havnt looked into the MAX funtion.. thanks ill look.

 

really this doesnt relate to php other than i would want to be using php with the row returned... (sorry i always get confused as to where mysql ends and php begins).

 

 

currently im thinking of something like this as a temporary fix.

 

    $query = mysql_query("SELECT * FROM table ORDER BY episode_id DESC LIMIT=1");

ok. I'm a total noob, but this is actually one that I can answer because I constantly fought a similar problem, so I'm kind of excited to finally give back.

 

The max() function will only return a value, the highest value, but if you're like me, you assume it will bring you the entire row with the highest value. It doesn't. I gives you a simple value. At that point, you have to select the row that matches that value. Only after you've selected the row can you join it with other tables. 


select * from t2 as t2 join 

(select col2, max(id) as id from t2 group by col2)as mx

on t2.id=mx.id

 

 

 

Hope this helps.

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.