0

I have been scratching my head on this and have done some google searches but can't figure out why this query returns the wrong SUM.

$points = $wpdb->get_results("Select SUM(points) as points from $sc WHERE division_id = '$divid' and participant_id = '$partid' and status = '1'");

If I go to the database and run just the following, it will work perfectly exactly how I need it to. But if I put it in the Wordpress Query Get_Results format, it returns wrong information.

Select SUM(points) as points from $sc WHERE division_id = '$divid' and participant_id = '$partid' and status = '1'

What am I Missing, does Wordpress utilize SUM differently?

Brett
  • 161
  • 4
  • 16
  • Follow https://stackoverflow.com/questions/303994/log-all-queries-in-mysql to log all sql queries. Once, you make changes, run the above sql from your wordpress app and check if you see the exact query being fired to database. – harshavmb Jun 06 '17 at 03:37
  • Thanks for the info, I can copy and past the query and get a different result from the database then from what is shown in logging the results. I am completely confused :) – Brett Jun 06 '17 at 04:18
  • So, are you seeing different results for the same query in sql logs? – harshavmb Jun 06 '17 at 04:32
  • That is correct. If I run the query from the logs in MySQL outside of the app I get 6, but when I display query results in the logs I get 2 – Brett Jun 06 '17 at 11:08
  • Can you paste both the queries and their outputs please? Though they are different, I want both the queries – harshavmb Jun 06 '17 at 11:12

0 Answers0