views:

128

answers:

3

the table videos has the folowing feels id,average,name how can i write the query, to select the name of video, which have the max average!!! i can do that vith two queries, by selecting the max(avege) from the table, and then find out the name, where ihe average equal to max!!! but i want to do that in one query!!! help me please!!!

A: 

SELECT id,name,MAX(average) FROM videos;

All fields you choose to SELECT will be returned. Getting more data back is just a case of SELECTing more fields.

jackbot
A: 

You can use an ORDER BY with a LIMIT:

SELECT id, average, name FROM videos ORDER BY average DESC LIMIT 1

ORDER BY average DESC orders the rows in order of descending average (i.e. the first row will have an average equal to MAX(average)). LIMIT 1 causes only the first row to be returned.

Phil Ross
+2  A: 

You don't need a group by for this, you just want to select the highest average!

SELECT * FROM videos ORDER BY average DESC LIMIT 1;
Mike Sherov