Issue
Hi guys so what I think I have to do is a double join, but I have done some research and still I am not quite sure how to do it ... hope you guys can give me a hand. So below are my tables.
As you probably see, the empresa is related to empresa_id on the second table, and id_user from the third table is related to id of the second table.
I've already done this query :
select users.username, COUNT(*) c
from form_reply
left join users on form_reply.id_user = users.id
GROUP BY id
but it only retrieves the number of rows of each user and I also want it's "empresa". I am expecting an output like this :
+--------+-+----------+
|Username|c| empresa |
+--------+-+----------+
| su |7|AccSystems|
+--------+-+----------+
Solution
use another join with empressa_table to combine 3 tables
select users.username,e.empresa, COUNT(*) c
from form_reply
join users on form_reply.id_user = users.id
join empressa_table e on users.empresa_id=e.id
GROUP BY users.username,e.empresa
Answered By - Fahmi
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.