RE: getting the highest number in 3 db fields?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If we're trying to get the max value between 3 columns in a row like
this:

Prolog	transmodal	asian
1		2		3

We'd want to get the value "3"

If you wanted to get the max out of three values in a row, you might do
something like this:

SELECT MAX(prolog, transmodal, asian) FROM sometable


I think that'd work.


But then there's mention of row1 vs row2 vs row3.. So I guess I'm
confused.

In which case, if we're looking at:


Name		Value
----		-----
Prolog	1
Transmodal	2
Asian		3

Then you'd do something like this:

SELECT Name, Max(Value) FROM sometable group by Name


You can do this in PHP as well, but make the DB server do all the work.
:)

-TG

> -----Original Message-----
> From: Dennis Seavers [mailto:deseavers@xxxxxxxxxxxxxx] 
> Sent: Friday, November 19, 2004 1:46 AM
> To: Louie Miranda
> Cc: php-general@xxxxxxxxxxxxx
> Subject: RE:  getting the highest number in 3 db fields?
> 
> 
> Try using the SQL aggregate function MAX() or the PHP function max()
> 
> 
> > [Original Message]
> > From: Louie Miranda <lmiranda@xxxxxxxxx>
> > To: <php-general@xxxxxxxxxxxxx>
> > Date: 11/18/2004 11:34:57 PM
> > Subject:  getting the highest number in 3 db fields?
> >
> > I have a db field of 3.
> >
> > - prolog
> > - transmodal
> > - asian
> >
> > I wish to get the highest number of those three, in 
> different fields.
> >
> > Im thingking of..
> >
> > if (row0 =< row1) ...
> >
> > how about row2?
> >
> > confused..
> >
> > -- 
> > Louie Miranda
> > http://www.axishift.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux