i have a stored procedure that has to retrieve data from multiple tables
something like
SELECT [AppointmentId]
,[ContactId]
,[Date]
,[BookedBy]
,[Details]
,[Status]
,[Time]
,[Type]
,[JobId]
,[AppointmentFor]
,(Select PersonFirstName from Person where Person_Id = [AppointmentFor]) As UserFirstName
,(Select PersonLastName from Person where Person_Id = [AppointmentFor]) As UserLastName
,(Select PersonFirstName from Person where Person_Id = [ContactId]) As ContactFirstName
,(Select PersonLastName from Person where Person_Id = [ContactId]) As ContactLastName
FROM [dbo].[Appointments]
my question is
there is any other more efficient way to do this? Or is this the right approach?
I am working on a Sql server 2008
Thanks
If i understand correctly you will need to use two joins, so that you can match on [AppointmentFor] and [ContactId].
I have also aliased the table, which is a good habit to get into when joined across mutiple tables.