views:

291

answers:

2

Please look at this image

alt text

here is 3 tables , and out i want is

uid from table1 industry from table 3 of same uid count of fid from table 2 of same uid

like in the sample example output will be 2 records

Thanks

+2  A: 

I don't see any relation with table 1. Here's an example using an inner join between the two tables and grouping by the uid:

SELECT 
  t3.uid, 
  t3.industry, 
  count(t2.fid) 
FROM 
  table3 t3 
INNER JOIN 
  table2 t2 ON t3.uid = t2.uid 
GROUP BY 
  t3.uid
Darin Dimitrov
i agree with this answer, there is no need to join table 1 here. you can use t3.uid and t2.uid to join them, and get all info required.
Faisal
although generally I agree with the answer, additional JOIN might have an effect of filtering out the rows for which UID is not in the Table1.Also, for the shown query to be correct, group by should contain `t3.insdustry` as well
van
+2  A: 

Try with this:

SELECT table1.uid,table3.industry,COUNT(table2.fid) 
FROM table1 
INNER JOIN table3 ON table1.uid=table3.uid
INNER JOIN table2 ON table1.uid=table2.uid
GROUP BY table1.uid, table3.industry

Table1 inner join is useless but could be useful if you'll need to retrieve city or mem_no; in this case, remember to add the field also in GROUP BY clause.

systempuntoout