Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4022894
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:31:57+00:00 2026-05-20T10:31:57+00:00

I have a strong feeling that all mathematical operations unnecessary to the query itself

  • 0

I have a strong feeling that all mathematical operations unnecessary to the query itself ought to be preformed outside of the query. For example:

$result = mysql_query(SELECT a, a*b/c as score FROM table)
while ($row = mysql_fetch_assoc($result))
{
    echo $row['a'].' score: '.$row['score'].<br>;
}

vs:

$result = mysql_query(SELECT a, b, c FROM table)
while ($row = mysql_fetch_assoc($result))
{
    echo $row['a'].' score: '.$row['a']*$row['b']/$row['c'].<br>;
}

the second option would usually be better, especially with complex table joins & such. This is my suspicion, I only lack confirmation . . .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:31:58+00:00Added an answer on May 20, 2026 at 10:31 am

    My feeling would be that doing the maths in the database would be slightly more efficient in the long run, given your query setup. With the select a,b,c version, PHP has to create 3 elements and populate them for each row fetched.

    With the in-database version, only 2 elements are created, so you’ve cut creation time by 33%. Either way, the calculation has to be done, so there’s not much in the way of savings there.

    Now, if you actually needed the b and c values to be exposed to your code, then there’d be no point in doing the calculation in the database, you’d be adding more fields to the result set with their attendant creation/processing/populating overhead.

    Regardless, though, you should benchmark both version. What works in one situation may be worse than useless in another, and only some testing will show which is better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an SDL problem, however I have the strong feeling that the problem
I have a really strong feeling that this question will either be closed or
Using t-sql, how can i find if all SQL Logins have strong passwords on
I have a strong use case for pre-allocating all the memory I need upfront
I simply have a string that looks something like this: 7,true,NA,false:67,false,NA,false:5,false,NA,false:5,false,NA,false All I want
I am learning about the different design patterns and I have a strong feeling
I have a feeling that this question is very simple, but I just can't
query level: beginner As part of a learning exercise I have written code that
I have a strong database background but very little practical experience with ms sql
I have a strong j2ee background, and I am trying to move to objective-c

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.