Hi, I have a 4 tables where de relationship are:

*=Primary Key

 TABLE_A            TABLE_B                         TABLE_B
TABLE_C
  name                     code_B                               name
code_B
 *code_A ====== code_A                             *code_B ====== code_B

code_A


TABLE_B            TABLE_D

name                     code_D

*code_B ======= code_B

code_A

I need a query where I have the a amount that a code of the Table A appeared
in Table B and the number of code of Table B that they had appeared in Table
C and Table D. I made this query:

"Select TABLE_A.*, count(TABLE_B.code_B), count(TABLE_C.code_C) from TABLE_A
left join TABLE_B on TABLE_B.code_A=TABLE_A.code_A left join TABLE_C on
TABLE_C.code_B = TABLE_B.code_B left join TABLE_D on TABLE_D.code_B =
TABLE_B.code_B group by TABLE_A.code_A".

The reply it comes multiplied for the number of times that appear in tables
B, C and D. Therefore if it has 1 register in B, 2 in C and 3 in D. Then it
appears 6 as reply in each item, being that it would have to appear 1, 2 and
3 respectively.

I am thankful very if somebody will be able to help me?

Best Regards,
Joao Pedro


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to