Solved

Joins

Posted on 2009-04-02
4
207 Views
Last Modified: 2012-05-06
How do pull all rows from the TimeCategory Table
SELECT     Employee.EmployeeNumber, Employee.EmployeeName, Employee.Surname, TimeCategory.TimeCategoryName, DailyHoursTimeCategories.Hours, 
                      DailyHoursTimeCategories.Minutes
FROM         Employee INNER JOIN
                      DailyHours ON Employee.EmployeeID = DailyHours.EmployeeID INNER JOIN
                      DailyHoursTimeCategories ON DailyHours.DailyHoursID = DailyHoursTimeCategories.DailyHoursID RIGHT OUTER JOIN
                      TimeCategory ON DailyHoursTimeCategories.TimeCategoryID = TimeCategory.TimeCategoryID

Open in new window

0
Comment
Question by:u2envy1
  • 2
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
dportas earned 500 total points
ID: 24048121
SELECT Employee.EmployeeNumber, Employee.EmployeeName, Employee.Surname,
 TimeCategory.TimeCategoryName, DailyHoursTimeCategories.Hours,
 DailyHoursTimeCategories.Minutes
FROM TimeCategory
LEFT OUTER JOIN DailyHoursTimeCategories
ON DailyHoursTimeCategories.TimeCategoryID = TimeCategory.TimeCategoryID
LEFT OUTER JOIN DailyHours
ON DailyHours.DailyHoursID = DailyHoursTimeCategories.DailyHoursID
LEFT OUTER JOIN Employee
ON Employee.EmployeeID = DailyHours.EmployeeID ;
0
 

Author Comment

by:u2envy1
ID: 24048571
Sorry wrong query. Suppose to add the GROUP BY query.
SELECT     Employee.EmployeeNumber, TimeCategory.TimeCategoryName, SUM(DailyHoursTimeCategories.Hours) AS Hours, 
                      SUM(DailyHoursTimeCategories.Minutes) AS Minutes
FROM         Employee INNER JOIN
                      DailyHours ON Employee.EmployeeID = DailyHours.EmployeeID INNER JOIN
                      DailyHoursTimeCategories ON DailyHours.DailyHoursID = DailyHoursTimeCategories.DailyHoursID RIGHT OUTER JOIN
                      TimeCategory ON DailyHoursTimeCategories.TimeCategoryID = TimeCategory.TimeCategoryID
GROUP BY TimeCategory.TimeCategoryName, Employee.EmployeeNumber

Open in new window

0
 
LVL 22

Expert Comment

by:dportas
ID: 24048839
Aren't the joins the same? Just put the GROUP BY and SUMs into my query above.
0
 

Author Closing Comment

by:u2envy1
ID: 31565708
Thx, I added them & it worked perfectly
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question