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.
| 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, RESULTDATEtblTRAINMODULE has columns: ID, MODULE_NAMEtblEMPLOYEE has columns: ID, FIRSTNAME, SURNAMEHopefully 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,RESULTDATEFROM(SELECT e.ID AS EmpID, e.FIRSTNAME, e.SURNAME,tm.ID AS TrainingID,tm.MODULE_NAMEFROM tblEMPLOYEE eCROSS JOIN tblTRAINMODULE tm)tLEFT JOIN tblTRAINASSESS taON ta.EMPLOYEE_ID = t.EmpIDAND ta.TRAINMODULE_ID = t.TrainingID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|