![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Considering the following tables is it possible to write an SQL query that would result in rows that look like (EmpID, CourseID, DateTaken) for each employee and each required course in one result set? 1 4 8/12/2005 1 5 8/12/2005 1 6 NULL 2 6 7/7/2006 2 4 NULL Employees(EmpID*, PosID) Positions(PosID*) Courses(CourseID*) RequiredCourses(CourseID*, PosID*) CompletedCourses(EmpID*, CourseID*, DateTaken*) |
#3
| |||
| |||
|
|
rkc wrote: Considering the following tables is it possible to write an SQL query that would result in rows that look like (EmpID, CourseID, DateTaken) for each employee and each required course in one result set? 1 4 8/12/2005 1 5 8/12/2005 1 6 NULL 2 6 7/7/2006 2 4 NULL Employees(EmpID*, PosID) Positions(PosID*) Courses(CourseID*) RequiredCourses(CourseID*, PosID*) CompletedCourses(EmpID*, CourseID*, DateTaken*) |
|
Just thinking out loud... what does this give you? SELECT cc.EmpID,cc.CourseID,cc.DateTaken FROM CompletedCourses cc, Employees e, RequiredCourses rc WHERE cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID AND rc.PosID = e.PosID ORDER BY cc.EmpID,cc.DateTaken; |
#4
| |||
| |||
|
|
rkc wrote: Considering the following tables is it possible to write an SQL query that would result in rows that look like (EmpID, CourseID, DateTaken) for each employee and each required course in one result set? 1 4 8/12/2005 1 5 8/12/2005 1 6 NULL 2 6 7/7/2006 2 4 NULL Employees(EmpID*, PosID) Positions(PosID*) Courses(CourseID*) RequiredCourses(CourseID*, PosID*) CompletedCourses(EmpID*, CourseID*, DateTaken*) Just thinking out loud... what does this give you? SELECT cc.EmpID,cc.CourseID,cc.DateTaken FROM CompletedCourses cc, Employees e, RequiredCourses rc WHERE cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID AND rc.PosID = e.PosID ORDER BY cc.EmpID,cc.DateTaken; |
#5
| |||
| |||
|
|
zac.carey (AT) gmail (DOT) com wrote: rkc wrote: Considering the following tables is it possible to write an SQL query that would result in rows that look like (EmpID, CourseID, DateTaken) for each employee and each required course in one result set? 1 4 8/12/2005 1 5 8/12/2005 1 6 NULL 2 6 7/7/2006 2 4 NULL Employees(EmpID*, PosID) Positions(PosID*) Courses(CourseID*) RequiredCourses(CourseID*, PosID*) CompletedCourses(EmpID*, CourseID*, DateTaken*) Just thinking out loud... what does this give you? SELECT cc.EmpID,cc.CourseID,cc.DateTaken FROM CompletedCourses cc, Employees e, RequiredCourses rc WHERE cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID AND rc.PosID = e.PosID ORDER BY cc.EmpID,cc.DateTaken; this should be right now... SELECT e.EmpID, rc.CourseID, cc.DateTaken FROM Employees e LEFT JOIN RequiredCourses rc ON rc.PosID = e.PosID LEFT JOIN CompletedCourses cc ON cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID LIMIT 0 , 30 |
#6
| |||
| |||
|
|
zac.carey (AT) gmail (DOT) com wrote: zac.carey (AT) gmail (DOT) com wrote: rkc wrote: Considering the following tables is it possible to write an SQL query that would result in rows that look like (EmpID, CourseID, DateTaken) for each employee and each required course in one result set? 1 4 8/12/2005 1 5 8/12/2005 1 6 NULL 2 6 7/7/2006 2 4 NULL Employees(EmpID*, PosID) Positions(PosID*) Courses(CourseID*) RequiredCourses(CourseID*, PosID*) CompletedCourses(EmpID*, CourseID*, DateTaken*) Just thinking out loud... what does this give you? SELECT cc.EmpID,cc.CourseID,cc.DateTaken FROM CompletedCourses cc, Employees e, RequiredCourses rc WHERE cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID AND rc.PosID = e.PosID ORDER BY cc.EmpID,cc.DateTaken; this should be right now... SELECT e.EmpID, rc.CourseID, cc.DateTaken FROM Employees e LEFT JOIN RequiredCourses rc ON rc.PosID = e.PosID LEFT JOIN CompletedCourses cc ON cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID LIMIT 0 , 30 I appreciate your efforts on my behalf. I have not tried the first query shown yet. The second one shown, with the Left Joins has Access (I'm working with an Jet/.mdb database) complaining about ambiguous joins and suggesting I create a seperate query that does the first join and include it in the other. So I'm am going see what I can do with that advice. |
#7
| |||
| |||
|
|
rkc wrote: zac.carey (AT) gmail (DOT) com wrote: zac.carey (AT) gmail (DOT) com wrote: rkc wrote: Considering the following tables is it possible to write an SQL query that would result in rows that look like (EmpID, CourseID, DateTaken) for each employee and each required course in one result set? 1 4 8/12/2005 1 5 8/12/2005 1 6 NULL 2 6 7/7/2006 2 4 NULL Employees(EmpID*, PosID) Positions(PosID*) Courses(CourseID*) RequiredCourses(CourseID*, PosID*) CompletedCourses(EmpID*, CourseID*, DateTaken*) Just thinking out loud... what does this give you? SELECT cc.EmpID,cc.CourseID,cc.DateTaken FROM CompletedCourses cc, Employees e, RequiredCourses rc WHERE cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID AND rc.PosID = e.PosID ORDER BY cc.EmpID,cc.DateTaken; this should be right now... SELECT e.EmpID, rc.CourseID, cc.DateTaken FROM Employees e LEFT JOIN RequiredCourses rc ON rc.PosID = e.PosID LEFT JOIN CompletedCourses cc ON cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID LIMIT 0 , 30 I appreciate your efforts on my behalf. I have not tried the first query shown yet. The second one shown, with the Left Joins has Access (I'm working with an Jet/.mdb database) complaining about ambiguous joins and suggesting I create a seperate query that does the first join and include it in the other. So I'm am going see what I can do with that advice. Sorry, I know nothing about Access - but, on the face of it, I can't see why it wouldn't work. Maybe Access doesn't like aliases? Try this: SELECT Employess.EmpID, RequiredCourses.CourseID, CompletedCourses.DateTaken FROM Employees LEFT JOIN RequiredCourses ON RequiredCourses.PosID = Employees.PosID LEFT JOIN CompletedCourses ON CompletedCourses.EmpID = Employees.EmpID AND CompletedCourses.CourseID = RequiredCourses.CourseID; |
#8
| |||
| |||
|
|
zac.carey (AT) gmail (DOT) com wrote: rkc wrote: zac.carey (AT) gmail (DOT) com wrote: zac.carey (AT) gmail (DOT) com wrote: rkc wrote: Considering the following tables is it possible to write an SQL query that would result in rows that look like (EmpID, CourseID, DateTaken) for each employee and each required course in one result set? 1 4 8/12/2005 1 5 8/12/2005 1 6 NULL 2 6 7/7/2006 2 4 NULL Employees(EmpID*, PosID) Positions(PosID*) Courses(CourseID*) RequiredCourses(CourseID*, PosID*) CompletedCourses(EmpID*, CourseID*, DateTaken*) Just thinking out loud... what does this give you? SELECT cc.EmpID,cc.CourseID,cc.DateTaken FROM CompletedCourses cc, Employees e, RequiredCourses rc WHERE cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID AND rc.PosID = e.PosID ORDER BY cc.EmpID,cc.DateTaken; this should be right now... SELECT e.EmpID, rc.CourseID, cc.DateTaken FROM Employees e LEFT JOIN RequiredCourses rc ON rc.PosID = e.PosID LEFT JOIN CompletedCourses cc ON cc.EmpID = e.EmpID AND cc.CourseID = rc.CourseID LIMIT 0 , 30 I appreciate your efforts on my behalf. I have not tried the first query shown yet. The second one shown, with the Left Joins has Access (I'm working with an Jet/.mdb database) complaining about ambiguous joins and suggesting I create a seperate query that does the first join and include it in the other. So I'm am going see what I can do with that advice. Sorry, I know nothing about Access - but, on the face of it, I can't see why it wouldn't work. Maybe Access doesn't like aliases? Try this: SELECT Employess.EmpID, RequiredCourses.CourseID, CompletedCourses.DateTaken FROM Employees LEFT JOIN RequiredCourses ON RequiredCourses.PosID = Employees.PosID LEFT JOIN CompletedCourses ON CompletedCourses.EmpID = Employees.EmpID AND CompletedCourses.CourseID = RequiredCourses.CourseID; Jet handles the aliases O.K. It's the last join where the ON criteria comes from two different tables. Remove either one and no error. |
#9
| |||
| |||
|
|
rkc wrote: zac.carey (AT) gmail (DOT) com wrote: Jet handles the aliases O.K. It's the last join where the ON criteria comes from two different tables. Remove either one and no error. I see, so it needs a derived table. Does this work? SELECT t1.EmpID, t1.CourseID, t1.DateTaken FROM (SELECT e.EmpID, e.PosID, rc.CourseID, cc.DateTaken FROM Employees e, RequiredCourses rc, CompletedCourses cc) t1 LEFT JOIN RequiredCourses ON RequiredCourses.PosID = t1.PosID LEFT JOIN CompletedCourses ON CompletedCourses.EmpID = t1.EmpID AND CompletedCourses.CourseID = t1.CourseID; |
#10
| |||
| |||
|
|
zac.carey (AT) gmail (DOT) com wrote: rkc wrote: zac.carey (AT) gmail (DOT) com wrote: Jet handles the aliases O.K. It's the last join where the ON criteria comes from two different tables. Remove either one and no error. I see, so it needs a derived table. Does this work? SELECT t1.EmpID, t1.CourseID, t1.DateTaken FROM (SELECT e.EmpID, e.PosID, rc.CourseID, cc.DateTaken FROM Employees e, RequiredCourses rc, CompletedCourses cc) t1 LEFT JOIN RequiredCourses ON RequiredCourses.PosID = t1.PosID LEFT JOIN CompletedCourses ON CompletedCourses.EmpID = t1.EmpID AND CompletedCourses.CourseID = t1.CourseID; This one runs. The problem is that it runs forever. Access will show the rows as it comes up with them and give a total count when the query stops running. The query never stops running and the rows it does return are not what I'm looking for. I'm beginning to think I have to run my original solution once for each employee and procedurally build a temp table. That is within my skill set. It just didn't seem right to have to do that. |
![]() |
| Thread Tools | |
| Display Modes | |
| |