Solved

Joins

Posted on 2009-04-02
4
200 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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