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 |
seekaye
Starting Member
6 Posts |
Posted - 2012-12-16 : 10:52:31
|
I have three tablesPupilStudyingPUPIL..SUBJECTAnna...MathsBill...MathsChas...MathsDave...MathsAnna...EnglishBill...EnglishChas...EnglishDave...EnglishSubjectListSUBJECT....TARGETTYPEMaths......NumeracyEnglish....LiteracyScience....GeneralPupilTargetsPUPIL......TARGETTYPE....TARGETAnna.......Numeracy......AChas.......Numeracy......DDave.......Numeracy......CAnna.......Literacy......BChas.......Literacy......BDave.......Literacy......EAnna.......General.......BChris......General.......BDave.......General.......EI would like to retrieve each students maths target with a null value for Bill as his is missingAnna ABill -Chas DDave CI've got as far asSELECTPS.Pupil,PT.Target,FROM((PupilsStudying PSINNER JOIN SubjectList SLON PS.subject=SL.subject)LEFT JOIN PupilsTargetsON PT.pupil=PS.pupil AND PT.targettype=SL.targettype)WHEREPS.SUBJECT='Maths'but get a “JOIN NOT SUPPORTED” error. It seems to be the PT.targettype=SL.targettype which it doesn’t like. I also have a second inner join and left join in the query which works when this part is removed so i've left them out for simplicityI'm using AccessAny help appreciated |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-12-16 : 16:36:23
|
One of these?--- 1SELECT ps.Pupil, pt.TargetFROM PupilStudying ps LEFT JOIN PupilTargets pt ON pt.pupil = ps.pupilWHERE ps.Subject = 'Maths';--- 2SELECT ps.Pupil, pt.TargetFROM PupilStudying ps LEFT JOIN SubjectList sl ON sl.Subject = ps.Subject LEFT JOIN PupilTargets pt ON pt.pupil = ps.pupil AND pt.TargetType = slTargetTypeWHERE ps.Subject = 'Maths'; |
|
|
seekaye
Starting Member
6 Posts |
Posted - 2012-12-16 : 17:14:10
|
thanks for your responsethe first suggestion returns more than one line for some students, if their english or general target is different from their maths.the second one still says join not supported.it is definitely the second bit of the join it doesn't likeLEFT JOIN PupilTargets pt ON pt.pupil = ps.pupil AND pt.TargetType = sl.TargetTypethe PT.TargetType=SL.TargetType, presumably because i'm not joining the pt table directly to the ps table but using a field from the sl table which i already joined on... |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-12-16 : 20:15:45
|
are you using SQL Server ? KH[spoiler]Time is always against us[/spoiler] |
|
|
seekaye
Starting Member
6 Posts |
Posted - 2012-12-17 : 01:15:52
|
I'm using VB.net with access |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-12-17 : 01:27:47
|
You have posted under a SQL Server forum. And solution suggested are for SQL Server. for MS Access question, you should post over at http://www.sqlteam.com/forums/forum.asp?FORUM_ID=3I am not MS Access expert, but you can tryFROM((PupilsStudying PS INNER JOIN SubjectList SL ON PS.subject=SL.subject) LEFT JOIN PupilsTargets PT ON PT.pupil=PS.pupil AND PT.targettype=SL.targettype) KH[spoiler]Time is always against us[/spoiler] |
|
|
|
|
|
|
|