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 |
|
afrausto
Starting Member
1 Post |
Posted - 2006-05-09 : 19:06:29
|
| I'm having trouble developing the query to get the data from two tables. Sounds simple, but it's driving me nuts.Table 1: tblProjectsPID ProjectName ApplicationComplete YearApplied1 Project 1 True 20062 Project 2 True 20063 Project 3 False 20054 Project 4 True 20065 Project 5 True 20046 Project 6 True 2006Table 2: tblScoresScoreID PID JudgeType Score1 1 Chairperson 52 2 Chairperson 73 2 Co-Chair 64 4 Chairperson 95 5 Chairperson 10 From the two tables I want to pull all the records from tblProjects that meet the following criteria:ApplicationComplete = True ANDYearApplied = '2006'As well, I would like to append the scores from tblScores where tblProjects.PID = tblScores.PID AND JudgeType = 'Chairperson'The results should be:ProjectName ScoreProject 1 5Project 2 7Project 4 9Project 6Although, Project 6 has not been given a score by a judge I still want it to appear in my results.I've tried Left and Right Join based on PID relationship between the two tables but the results never shows records for Projects that have not been giving a score by a Chairperson.Any assistance with this is greatly appreciated. Cheers!afrausto |
|
|
nosepicker
Constraint Violating Yak Guru
366 Posts |
Posted - 2006-05-09 : 19:47:56
|
| How about this:SELECT tblProjects.ProjectName, tblScores.Score FROM tblProjects LEFT JOIN tblScores ON tblProjects.pid = tblScores.pid AND tblScores.JudgeType = 'Chairperson' WHERE tblProjects.ApplicationComplete = 'True' AND tblProjects.YearApplied = '2006' |
 |
|
|
|
|
|