Home How to get count by combining more than 2 tables in mysql

# How to get count by combining more than 2 tables in mysql

user3292629
1#
user3292629 Published in 2017-12-07 18:23:14Z
 i have a table 'A' with status column, it can have 4 values. In table A i have table 'B's id, table B have table 'C's id. I want to get the status count FROM table 'A' by joining all these columns. The status column in table A is a foreign key from table 'D'. Table 'D' having status like 1-agreed, 2-not agreed etc
ATrimeloni
2#
 The question is missing some information that might be helpful. Particularly, what exactly you are wanting to count. (i.e. are you just trying to count ALL rows, or are you trying to count the number of rows in table A that have each status). I'll put together an answer that assumes that latter. I'll also just assume that "id" is the primary key of its own table, and that id will be the id from other tables inside a table. select A.statusField, count(*) from A join B on (A.Bid = B.id) join C on (B.Cid = C.id) group by A.statusField  Hope that helps.