Get the highest result from a msql_query using php?

Get the highest result from a msql_query using php?

am 01.12.2007 11:24:17 von cronoklee

I have a result resource from a large mysql query and I need to find
the single the highest value from a certain field. What's the best way
to pull it off?
Cheers,
Ciar=E1n

Re: Get the highest result from a msql_query using php?

am 01.12.2007 11:43:42 von Shelly

Ciaran wrote:
> I have a result resource from a large mysql query and I need to find
> the single the highest value from a certain field. What's the best way
> to pull it off?
> Cheers,
> CiarĂ¡n

A simple google of "sql max" would have led you to:
SELECT MAX(expression )
FROM tables
WHERE predicates;

--

Shelly

Re: Get the highest result from a msql_query using php?

am 01.12.2007 12:00:30 von cronoklee

On Dec 1, 10:43 am, "Shelly" wrote:
> Ciaran wrote:
> > I have a result resource from a large mysql query and I need to find
> > the single the highest value from a certain field. What's the best way
> > to pull it off?
> > Cheers,
> > Ciar=E1n
>
> A simple google of "sql max" would have led you to:
> SELECT MAX(expression )
> FROM tables
> WHERE predicates;
>
> --
>
> Shelly

Thanks Shelly but I'm not great with sql and my query is already huge.
I don't think I'll be able to modify it to include the max as well as
everything else. Not to worry - I'm going to split the results into a
3d array and then try to sort it with php.
Thanks for the help

Re: Get the highest result from a msql_query using php?

am 01.12.2007 17:46:59 von Jonas Werres

> Thanks Shelly but I'm not great with sql and my query is already huge.
> I don't think I'll be able to modify it to include the max as well as
> everything else. Not to worry - I'm going to split the results into a
> 3d array and then try to sort it with php.
> Thanks for the help

So, you go to the library, take all the books, reorganise them, search
for the one you want to read and return the rest?

Re: Get the highest result from a msql_query using php?

am 01.12.2007 23:52:20 von Animesh Kumar

Jonas Werres wrote:
>> Thanks Shelly but I'm not great with sql and my query is already huge.
>> I don't think I'll be able to modify it to include the max as well as
>> everything else. Not to worry - I'm going to split the results into a
>> 3d array and then try to sort it with php.
>> Thanks for the help
>
> So, you go to the library, take all the books, reorganise them, search
> for the one you want to read and return the rest?

Nice comparison there.

Re: Get the highest result from a msql_query using php?

am 02.12.2007 00:03:37 von Csaba

"Jonas Werres" wrote in message
news:47519002$0$13116$9b4e6d93@newsspool2.arcor-online.net.. .
>> Thanks Shelly but I'm not great with sql and my query is already huge.
>> I don't think I'll be able to modify it to include the max as well as
>> everything else. Not to worry - I'm going to split the results into a
>> 3d array and then try to sort it with php.
>> Thanks for the help
>
> So, you go to the library, take all the books, reorganise them, search for
> the one you want to read and return the rest?

No, you throw the rest away! ;)

R.

Re: Get the highest result from a msql_query using php?

am 02.12.2007 04:10:34 von cronoklee

Actually, I'm using all returned records further down my page - I just
want to pull the newest one to reference at the top.
Not to worry - the php is working out better for my design and I
almost have it sorted now anyway.
Cheers,
Ciar=E1n

Re: Get the highest result from a msql_query using php?

am 02.12.2007 11:32:51 von Jonas Werres

> Not to worry - the php is working out better for my design and I
> almost have it sorted now anyway.
And I am almost sure, that even a second query would work out better.

Re: Get the highest result from a msql_query using php?

am 03.12.2007 13:33:27 von AnrDaemon

Greetings, Ciaran.
In reply to Your message dated Sunday, December 2, 2007, 06:10:34,

> Actually, I'm using all returned records further down my page - I just
> want to pull the newest one to reference at the top.
> Not to worry - the php is working out better for my design and I
> almost have it sorted now anyway.

Why You aren't using SQL ORDER BY clause then?
Using it properly You'll be always sure that Your newest entry is always on
the top of query result.


--
Sincerely Yours, AnrDaemon