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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-03-17 : 08:17:38
|
| John writes "Problem with building SQL to select columns from three joined tables, all of which can have an outer join to a fourth table. Environment is SQL Server 2000.Here is a simplified version of schema: EveTable: EveTableId (key) Title OrgTableId LocTableId ImageId (can be null)EveTable Joins to: OrgTable: OrgTableId (key) Title ImageId (can be null) EveTable also Joins to: LocTable: LocTableId (key) Title ImageId (can be null)All three tables join to: ImgTable Title ImageId Title Problem: I wish to: Select EveTable.Title, LocTable.Title, OrgTable.Title, ImgTable.Title [all] where EveTableID=nI am currently stuck at building even the basic SQL for this! Best Regards," |
|
|
druer
Constraint Violating Yak Guru
314 Posts |
Posted - 2006-03-17 : 09:26:10
|
| select .....from EveTable left outer join OrgTable on EveTable.OrgTableId = OrgTable.OrgTableId left outer join LocTable on EveTable.LocTableId = LocTable.LocTableId left outer join ImgTable on EveTable.ImageId = ImgTable.ImageIdBest advice is always start small and work your way up to the more complex joins. Just try and join EveTable to the OrgTable first. The other option is use the query designer in Enterprise Manager so you can see the constructs. Just go to Enterprise manager and right click on the EveTable and choose Open/Query then it will bring up a query designer window and allow you to add the OrgTable and make the join visually then see what the sql command looks like when you do that.Hope it helps,Dalton |
 |
|
|
|
|
|