here's a couple of guidelines for how to approach such a problem
1. write the joins by always joining just one more table to the ones you've already got (going from left to right)
this means don't try to join a pair of tables
you start with tbl95view1 then tbl88view2 then tbl91view1
(aside: if these are the real table names, you need saved queries or views to give them some more meaningful names, and if you've picked those names to preserve confidentiality in your postings here, then you could just as easily call them curly, larry, and moe -- anything would be better than those horrid numbered names, which, i am confident you have already found out yourself, are so susceptible to typos)
but then after the first three, you next try to join a join of tbl45 and tbl47
so, just one at a time, going from left to right
2. if you need to LEFT OUTER to any tables, put them after all the INNER joins
3. if you need to join any table to a table that was joined by LEFT OUTER, then use LEFT OUTER for those as well
so i would change this --
FROM (((((tbl95view1
INNER JOIN tbl88view2 ON tbl95view1.col35 = tbl88view2.col20)
INNER JOIN tbl91view1 ON tbl88view2.col1 = tbl91view1.col13)
INNER JOIN (tbl45 INNER JOIN tbl47 ON tbl45.col2 = tbl47.col1) ON tbl88view2.col13 = tbl45.col1)
LEFT JOIN tbl53 ON tbl91view1.col23 = tbl53.col1)
LEFT JOIN tbl63 ON tbl91view1.col27 = tbl63.col1)
INNER JOIN tbl71 ON tbl63.col4 = tbl71.col1
to this --
FROM ((((((tbl95view1
INNER JOIN tbl88view2 ON tbl95view1.col35 = tbl88view2.col20 )
INNER JOIN tbl91view1 ON tbl88view2.col1 = tbl91view1.col13 )
INNER JOIN tbl45 ON tbl88view2.col13 = tbl45.col1 )
INNER JOIN tbl47 ON tbl45.col2 = tbl47.col1 )
LEFT JOIN tbl53 ON tbl91view1.col23 = tbl53.col1 )
LEFT JOIN tbl63 ON tbl91view1.col27 = tbl63.col1 )
LEFT JOIN tbl71 ON tbl63.col4 = tbl71.col1
here is a "diagram" which illustrates how the tables are joined
Code:
-- 45 -- 47
/
95 -- 88 -- 91 -- 53
\
-- 63 -- 71
one worrisome conclusion to draw from this diagram is that if there is any 1-to-many relationship along the paths that diverge from 88 and 91, then you will have a cross join or cartesian effect
Bookmarks