Search code examples
phpsqlmysqlcountinner-join

mysql join 3 tables and count


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


Solution

  • 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