I have a UNION statement to combine scores for students from two different tables (MySQL 5.6). It is returning inconsistent results. When I run each statement independently, they generate the right results for all students. When I combine them with the UNION, it is correct for all but one student.
Even stranger, if I remove any one of the items being added from the first query, it sums correctly for ALL records.
For instance, removing sum(ifnull(owl_tracker.pre_req_points,0))
or sum(ifnull(owl_tracker.bonus_points,0))
from the query causes it to return correct results for all students.
select first_name, last_name, location, sum(total_points) as total_points from (
select first_name, last_name, location, (
sum(ifnull(owl_tracker.pre_req_points,0)) +
sum(ifnull(owl_tracker.bonus_points,0)) +
sum(ifnull(owl_tracker.a_points,0))) AS total_points
from products, students_products, students
Fiddle here: http://sqlfiddle.com/#!9/7ea891/1
Student A works correctly but Student B does not.