Re: getting only the largest or smallest values in a select statement

From: Date: Fri, 06 Oct 2000 23:17:40 +0000
Subject: Re: getting only the largest or smallest values in a select statement
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-19001@lists.php.net to get a copy of this message
On Fri, 06 Oct 2000, Dave Gardner wrote: > How can I get the largest (or smallest) value of a column in multiple > records, culled from a select statement? Let's say I did a 'select id, > amount from purchases' and got the following: > > id amount > -- ------- > 1 488 > 2 1256 > 3 188 > 4 97 > 5 166 > > Is it possible to modify the query itself to select only the largest or > smallest value in 'amount' as displayed here? Or is there something I need > to do in PHP to figure that out? SELECT max(amount) AS largest FROM table; SELECT min(amount) AS smallest FROM table; That should work for you. (If I'm remembering my SQL correctly..heh) -- James Atkinson ----------------------------------------------------------------- James Atkinson 100world Technical Developer 512-1529 West 6th Avenue phone: +1-604-637-8122 Vancouver, BC, V6J 1R1 fax: +1-604-742-1770 Canada email: james.atkinson@100world.com http://www.100world.com +---------------------------------------------------------------+ | This message may contain confidential and/or privileged | | information. If you are not the addressee or authorized to | | receive this for the addressee, you must not use, copy, | | discolse or take any action based on this message or any | | information herein. If you have received this message in | | error, please advise the sender immediately by reply e-mail | | and delete this message. Thank you for you cooperation | +---------------------------------------------------------------+

« previous php.general (#19001) next »