I know how to calculate the maximum value of the whole table:
[php]$res = mysql_query( "SELECT max( field ) FROM table" );[/php]
But how would I calculate the maximum value of the first 10 items or item 10 - 20?
Not shure about Mysql but in T-SQL you can do
[code]
select TOP 10 MAX(Field) from Table
[/code]
And for the second, you should be able to do
[code]
select TOP 20 MAX(Field) from Table ORDER BY Field DESC Limit 10
[/code]
Should only work in Mysql
[code]SELECT MAX( field ) FROM (SELECT field FROM table ORDER BY id LIMIT 10)[/code]
I've ordered by 'id' there, as MySQL's default sort order is undefined, so you might not get the actual first 10
Your example didn't work, I used a subquery to do the job:
[php]$res = mysql_query( "SELECT max( field ) FROM ( SELECT * FROM table LIMIT 0, 5 ) AS subtbl" )[/php]
[b]Edit:[/b] Hey, Turbulence. :ninja:
Sorry, you need to Log In to post a reply to this thread.