Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SELECT Where Records Arent There

Author  Topic 

hobbsieoz
Starting Member

2 Posts

Posted - 2011-09-02 : 06:56:51
I have a table of employess with 1049 records, and a table of training assessment results, and a table of training modules with 209 records.

What im trying to do is for each employee is see if they have a training result for each module, if there is then bring back their result and if there isnt just bring back null as the result. So in theory i should have 219241 records back.

How can i do this? Im getting slightly confused by the joins as its only bringing back records where there is a training record.

tblTRAINASSESS has columns: EMPLOYEE_ID, TRAINRESULT, TRAINMODULE_ID, RESULTDATE

tblTRAINMODULE has columns: ID, MODULE_NAME

tblEMPLOYEE has columns: ID, FIRSTNAME, SURNAME

Hopefully somebody can shed some light for me on this. Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-02 : 07:01:20
[code]SELECT EmpID,FIRSTNAME,SURNAME,MODULE_NAME,TRAINRESULT,RESULTDATE

FROM
(
SELECT e.ID AS EmpID,
e.FIRSTNAME,
e.SURNAME,
tm.ID AS TrainingID,
tm.MODULE_NAME
FROM tblEMPLOYEE e
CROSS JOIN tblTRAINMODULE tm
)t
LEFT JOIN tblTRAINASSESS ta
ON ta.EMPLOYEE_ID = t.EmpID
AND ta.TRAINMODULE_ID = t.TrainingID
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -