p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: RE: Nick Selecting the record with the greatest number


Message #1 by "jorge" <jorge@d...> on Wed, 4 Sep 2002 17:15:52 -0500
Hey Nick you have cheated he ask for a single query;
I told him not possible
seconde query ccould be taken from any of the other set of results with the
same end result

:)
Jorge




----- Original Message -----
From: "Nikolai Devereaux" <yomama@u...>
To: "beginning php" <beginning_php@p...>
Sent: Wednesday, September 04, 2002 1:45 PM
Subject: [beginning_php] RE: Selecting the record with the greatest number


>
> Okay, the difference between Jorge's solution and your needs is that he's
> _NOT_ returning the original values of refCount and revCount in the SELECT
> clause, and you need them.
>
> This is one of the many places where mysql's lack of nested-query support
> would be ideal:
>
> SELECT C1.contribName, C1.revCount, C1.refCount
>   FROM contest C1
>  WHERE (C1.revCount + C1.refCount) 
>          (SELECT MAX(C2.revCount + C2.refCount)
>             FROM contest C2
>          )
>
>
> To do this with mySQL, you might need to just pull things apart:
>
> $query  = "SELECT MAX(revCount + refCount) FROM contest";
> $result = mysql_query($query);
> $max    = mysql_result($result, 0);
>
> $query = "SELECT contribName, revCount, refCount
>             FROM contest
>            WHERE (revCount + refCount) = $max";
> $result = mysql_query($query);
> // you know the rest...
>
>
>
> Take care,
>
> Nik
>
>



  Return to Index