Aggregate/Scalar or via code?



I hope that is not too vague of a question.

I have begun taking a database class in school, which is where this question spawned from.

If I were to use the aggregate or scalar functions for example, are they preferred over
using code (such as PHP, VB/ASP et cetera)?

An example of this is:

SELECT AVG(column_name) FROM table_name

....whereas with PHP it would be:

// retrieve the entire column via a query, then

function average($_array_of_average_inputs)
{
return array_sum($_array_of_average_inputs) / count($_array_of_average_inputs);
}

$avg = average($average_array);

....and on and on. Or something like:

SELECT UCASE(column_name) FROM table_name

....whereas with PHP it would be:

// retrieve the entire column via a query, then

$final_result = strtoupper($ascii_results_of_query);

So, sorry if I rambled on a bit. As per the norm I am tired as hell and its 4AM. I just
want to figure out (or learn) which is faster. Do the operation via SQL if possible and
then store it, or issue vanilla queries and do everything myself with code.

Thanks and sorry for the incoherence (if any exists)!

-Lost


.



Relevant Pages

  • Re: Aggregate/Scalar or via code?
    ... If I were to use the aggregate or scalar functions for example, are they preferred over using code (such as PHP, VB/ASP et cetera)? ... // retrieve the entire column via a query, ... Do the operation via SQL if possible and then store it, or issue vanilla queries and do everything myself with code. ...
    (alt.php)
  • about unicode
    ... how i can retrieve this data in php page i have tried using simple sql ... query but it shows only "???????????" ...
    (comp.lang.php)
  • Retrieve One Row Of MySQL
    ... How do I retrieve only one row of database info? ... $query = mysql_query; ...
    (comp.lang.php)
  • [ENG] record count
    ... I've to retrieve in MySQL the record number ). ... I can't use PHP for this, I absolutely need it in the mysql record. ... in the query? ...
    (de.comp.datenbanken.mysql)
  • Re: Confused by mysqli
    ... When I started using MySQL with Perl back in 1998, ... fetch_assocon a query I prepared with bind variables, ... So I had it print out its eval string that it was trying to run. ... PHP will fail to run at all, because bind_result will not have enough ...
    (comp.lang.php)