View Single Post
Join Date: Apr 2008
Posts: 296
Reputation: tesuji is on a distinguished road 
Solved Threads: 42
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: Problem using JOIN with six tables

 
0
  #5
May 11th, 2008
hi recursiveNugget,

bad news! I have checked your join operations on those 6 tables, and the (wrong) results are:

1. contact.id
id 2 will be counted 20 times
id 5 will be counted 16 times
id 8 will be counted 4 times

2. Indeed, you need LEFT OUTER JOIN. With inner join (which would be the appropriate one
for such tasks, but...) you would lose all information about contact.id 2 and 8.

3. However, the result is wrong because you join four tables (tdocumentsA..D) independently
together. The information you have spread over these 4 table MUST be arranged in ONE
table only. Then applying of INNER JOIN on tusers INNER JOIN tContacts INNER JOIN
tdocuments would work properly.

Long story short, you need to redesign your tables.

krs,
tesu


Btw, below is the result of the last join, where you can check out why inner join would produce poorer results (all rows containing (NULL) would then disappear)
  1. # DocA DocB DocC DocD
  2. 1 1 2 C2 A1 B3 (NULL) D1
  3. 1 1 2 C2 A1 B4 (NULL) D1
  4. 1 1 2 C2 A1 B6 (NULL) D1
  5. 1 1 2 C2 A1 B7 (NULL) D1
  6. 1 1 2 C2 A1 B8 (NULL) D1
  7.  
  8. 1 1 2 C2 A1 B3 (NULL) D3
  9. 1 1 2 C2 A1 B4 (NULL) D3
  10. 1 1 2 C2 A1 B6 (NULL) D3
  11. 1 1 2 C2 A1 B7 (NULL) D3
  12. 1 1 2 C2 A1 B8 (NULL) D3
  13.  
  14. 1 1 2 C2 A1 B3 (NULL) D4
  15. 1 1 2 C2 A1 B4 (NULL) D4
  16. 1 1 2 C2 A1 B6 (NULL) D4
  17. 1 1 2 C2 A1 B7 (NULL) D4
  18. 1 1 2 C2 A1 B8 (NULL) D4
  19.  
  20. 1 1 2 C2 A1 B3 (NULL) D8
  21. 1 1 2 C2 A1 B4 (NULL) D8
  22. 1 1 2 C2 A1 B6 (NULL) D8
  23. 1 1 2 C2 A1 B7 (NULL) D8
  24. 1 1 2 C2 A1 B8 (NULL) D8
  25.  
  26. 3 1 5 C5 A3 B2 C5 D5
  27. 3 1 5 C5 A4 B2 C5 D5
  28. 3 1 5 C5 A5 B2 C5 D5
  29. 3 1 5 C5 A8 B2 C5 D5
  30.  
  31. 3 1 5 C5 A3 B2 C6 D5
  32. 3 1 5 C5 A4 B2 C6 D5
  33. 3 1 5 C5 A5 B2 C6 D5
  34. 3 1 5 C5 A8 B2 C6 D5
  35.  
  36. 3 1 5 C5 A3 B2 C5 D5
  37. 3 1 5 C5 A4 B2 C5 D5
  38. 3 1 5 C5 A5 B2 C5 D5
  39. 3 1 5 C5 A8 B2 C5 D5
  40.  
  41. 3 1 5 C5 A3 B2 C6 D6
  42. 3 1 5 C5 A4 B2 C6 D6
  43. 3 1 5 C5 A5 B2 C6 D6
  44. 3 1 5 C5 A8 B2 C6 D6
  45.  
  46. 4 1 8 C8 A6 (NULL) C2 (NULL)
  47. 4 1 8 C8 A7 (NULL) C2 (NULL)
  48. 4 1 8 C8 A6 (NULL) C2 (NULL)
  49. 4 1 8 C8 A7 (NULL) C2 (NULL)
Reply With Quote