Solved

Joins

Posted on 2009-04-02
4
183 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
Comment Utility
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
Comment Utility
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
Comment Utility
Aren't the joins the same? Just put the GROUP BY and SUMs into my query above.
0
 

Author Closing Comment

by:u2envy1
Comment Utility
Thx, I added them & it worked perfectly
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now