Please look at this image
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
It is possible to use multiple join statements together to join more than one table at the same time. To do that you add a second INNER JOIN statement and a second ON statement to indicate the third table and the second relationship.
At some point, you probably wondered if it's possible to join 3 tables in SQL or even more tables using the JOIN keyword. The short answer is, yes, it's possible! The longer answer is, yes, it's possible, and we will show you how to join 3 or more tables in SQL on a concrete job interview question.
for joining two tables, we require 1 join statement and for joining 3 tables we need 2 join statements.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With