Languages :: PHP :: mysql selecting max |
|||
| By: Bernard |
Date: 26/09/2005 09:24:53 |
Points: 20 | Status: Answered Quality : Excellent |
| how to retrieve the max of a column over a MySql database in PHP ? I can't get the returned value... | |||
| By: VGR | Date: 26/09/2005 09:30:59 | Type : Answer |
|
| Hello ;-) This is a very basic operation, and is more than well described in the documentations for PHP or MySql (www.mysql.com and www.php.net/manual/en/ or the like) so I suppose your problem is the "classical" alias problem : if you do select max(somecol) from thetable; then you will have the problem of retrieving "max(somecol)" as the name of the returned field. This can become tricky if the computation involves quotes, and can even get confusing if the RDBMS returns "computed" in stead of the formula itself ;-))So I suggest to always alias your computed columns, even if a simple count(*), like this : select sum(somecol) AS a from thetable; this way, you will probably have no problems at all retrieving the column named 'a' in the returned result set ;-) Note that some "RDBMS" do not support "AS" (Oracle, not to name it) but accept the aliasing without 'AS', like in "select sum(somecol) a from thetable") Best regards |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








