General information
Category:
Coding, syntax & commands
I'm having a problem with an SQL statement.
select course.courseid, coursematerial.textid, sum(textbook.cost);
from course left join coursematerial on course.courseid = coursematerial.courseid, textbook;
into table temptext;
group by course.courseid
The course table contains all the information of a course
The coursematerial table has courseid and the textid.
The textbook table has the costs for that textid.
I need all the course costs even if there are no textbooks for that course. So I use a left join to select all the courses from the course table and the ones that do match in the courematerial table.
So I should get a null value for the textid and the sum_cost. The problem is I get a sum for one of the courses even though it doesn't have any textbooks.
Here is the results of my SQL statement.
CourseID TextID Sum_cost
1000 cit155 12.4
2000 TR234 168.35
TTC108 NULL 168.35
TTC108D 123RT4 505.35
I don't know if that is clear enough, but I need some help.
Thanks, in advance,
Tyler
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only