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 |
|
popupsql
Starting Member
5 Posts |
Posted - 2009-09-29 : 04:32:00
|
| helloi have problem with query can anybody help me?Show tutor id & name & student id & name for each allocation. The list must be in tutorid sequence. Include all tutors even if they have not been allocated any students.this is my schema for tables STUDENT , TUTOR,ALLOCATION--STUDENT (StuId,StuSurname,StuFirstname,StuGender,City)--PK is StuId--FK is City References LOCATION--TUTOR (TutorId,TutorFirstname,TutorSurname,TutorGender,HourlyRate,WorkUniCode,StudiesUniCode,City)--PK is TutorId--FK is WorkUniCode References UNIVERSITY --FK is StudiesUniCode References UNIVERSITY--FK is City References LOCATION--ALLOCATION (TutorId,StuId)--PK is (TutorId,StuId)--FK is TutorId References TUTOR--FK is StuId References STUDENTi think i need to use tow outer join for this but it dosent work. please help me. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-09-29 : 04:44:32
|
can you show us your query ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
popupsql
Starting Member
5 Posts |
Posted - 2009-09-29 : 04:57:38
|
| yes here is my querySELECT TU.TutorId,TU.TutorFirstname,AL.StuId,ST.StuFirstnamefrom ALLOCATION ALLEFT OUTER JOIN STUDENT STON AL.StuId=ST.StuIdLEFT OUTER JOIN TUTOR TUON AL.TutorId=TU.TutorIdorder by TU.TutorId; |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-29 : 05:20:14
|
Take table TUTOR in FROM clause because you want all tutors.Left join the table ALLOCATION to the table TUTOR on TutorId.Left join the table STUDENT to the table ALLOCATION on StuId. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
popupsql
Starting Member
5 Posts |
Posted - 2009-09-29 : 05:30:03
|
[quote]Originally posted by webfred Take table TUTOR in FROM clause because you want all tutors.Left join the table ALLOCATION to the table TUTOR on TutorId.Left join the table STUDENT to the table ALLOCATION on StuId.you mean like thisSELECT TU.TutorId,TU.TutorFirstname,A.StuId,S.StuFirstnamefrom TUTOR TULEFT OUTER JOIN ALLOCATON AON TU.TutorId=A.TutorIdLEFT OUTER JOIN STUDENT SON S.StuId=A.StuIdorder by TU.TutorId; |
 |
|
|
popupsql
Starting Member
5 Posts |
Posted - 2009-09-29 : 05:34:35
|
| Thank you dear webfredit works now.cheers |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-29 : 06:06:14
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|