Jump to content

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.

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.