sql server - Joining multiple tables to one table in sql -


i have rather complex (well me) sql query happening , having trouble concepts.

i have following sql on webpage building

select      [dbo].[enrolment].[_identity], [dbo].[enrolment].commencementdate,      [dbo].[enrolment].completiondate, [dbo].[enrolment].enrolmentdate,      [dbo].[course].name coursename, [dbo].[course].identifier qualcode,      [dbo].[person].givenname, [dbo].[person].surname,[dbo].[employer].name empname,      [dbo].[employer].address1,[dbo].[employer].suburb,[dbo].[employer].phone,     [dbo].[employer].postcode,[dbo].[enrolmentstatus].name enrolname,      [dbo].[student].identifier,[dbo].[student].person,[dbo].[contact].person contactid      (((([dbo].[enrolment]  left join      [dbo].[course] on [dbo].[enrolment].course = [dbo].[course].[_identity]) left join      [dbo].[employer] on [dbo].[enrolment].employer = [dbo].[employer].[_identity])  left join      [dbo].[enrolmentstatus] on [dbo].[enrolment].status = [dbo].[enrolmentstatus].[_identity]) left join      [dbo].[student] on [dbo].[enrolment].student = [dbo].[student].[_identity])  left join      [dbo].[person] on [dbo].[student].person = [dbo].[person].[_identity]  left join      [dbo].[contact] on [dbo].[employer].[_identity] = [dbo].[contact].employer       (([dbo].[enrolmentstatus].name) = 'training'      or     ([dbo].[enrolmentstatus].name) = 'enrolled')  

this working fine join [dbo].[person] table again time joining table code need patch above statement is

left join      [dbo].[trainer] on [dbo].[enrolment].trainer = [dbo].[trainer].[_identity])  left join      [dbo].[person] on [dbo].[trainer].person = [dbo].[person].[_identity] 

i need able person table name of student , name of trainer, need 2 records person table every record enrolment table, fields need person table same both trainer , student in trying given name , surname both.

any or pointers appreciated.

use aliasing this..

left join [dbo].[trainer] on [dbo].[enrolment].trainer = [dbo].[trainer].[_identity]) left join [dbo].[person] p on [dbo].[trainer].person = p.[_identity] 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -