View Single Post
Join Date: Feb 2008
Posts: 36
Reputation: huangzhi is an unknown quantity at this point 
Solved Threads: 12
huangzhi huangzhi is offline Offline
Light Poster

Re: Problem using JOIN with six tables

 
0
  #6
May 12th, 2008
Try this code
  1. SELECT c.name, isNull(doc_A.Doc_A, 0) AS Doc_A, isNull(doc_B.Doc_B, 0) AS Doc_B, isNull(doc_C.Doc_C, 0) AS Doc_C, isNull(doc_D.Doc_D, 0) AS Doc_D
  2. FROM tUsers u INNER JOIN tContacts c ON
  3. u.contact_id = c.id LEFT JOIN (SELECT user_id, count(*) AS Doc_A FROM tDocumentsA GROUP BY user_id) Doc_A ON
  4. c.id = Doc_A.user_id LEFT JOIN (SELECT user_id, count(*) AS Doc_B FROM tDocumentsB GROUP BY user_id) Doc_B ON
  5. c.id = Doc_B.user_id LEFT JOIN (SELECT user_id, count(*) AS Doc_C FROM tDocumentsC GROUP BY user_id) Doc_C ON
  6. c.id = Doc_C.user_id LEFT JOIN (SELECT user_id, count(*) AS Doc_D FROM tDocumentsD GROUP BY user_id) Doc_D ON
  7. c.id = Doc_D.user_id
  8. WHERE u.location = 1
Hence Wijaya
www.ex-Soft.tk
Reply With Quote