I have the following two tables:
lab_assistant
la_id - la_firstname - la_lastname
1 - Dennis - Rodman
2 - Michael - Jordan
3 - Horace - Grant
hours_worked
hw_semester - hw_date - hw_hours - la_id
Fall 2012 - 2012-11-01 - 4 - 2
Fall 2012 - 2012-11-04 - 5 - 3
Spring 2012 - 2012-02-12 - 4 - 1
Spring 2012 -2012-03-10 - 4 - 1
The result of my query is supposed to look like the following:
and I'm trying to run the following query in order to list the Lab Assistant and the number of hours they worked each semester
SELECT DISTINCT(CONCAT(la.la_firstname, ' ', la.la_lastname)) AS 'Lab Assistant',
hw.hw_semester AS 'Semester Worked', hw.hw_hours AS 'Hours Worked'
FROM lab_assistant la
JOIN hours_worked hw
ON la.la_id = hw.la_id;
The results of my quere are SUPPOSED to look like this:
Michael Jordan - Fall 2012 - 4
Horace Grant - Spring 2012 - 5
Dennis Rodman - Fall 2012 - 8
BUT the results I'm getting are as follows:
Michael Jordan - Fall 2012 - 4
Horace Grant - Fall 2012 - 5
Dennis Rodman - Spring 2012 - 4
So basically, it just isn't counting the proper hours for Dennis Rodman. It should be 8 and not 4.
And I probably shouldn't use DISTINCT here because it's possible the same person could work different semesters.