Skip to content
Advertisement

Multiple joins in mysql with 3 tables

i have 3 tables

Here each item is owned by as user type “owner”

Each item is also associated by a user type “admin”

what I want is list of branches and associated total amount and total count

How can i do it in single query

i tried this which is showing amount of all branches

but I am getting same count and amount in all branches

Advertisement

Answer

I am not sure what you want from the query, so I have taken a guess. My answer query finds the total count and totaled amounts for the items linked to each branch, first by owner and then by admins.

In your query, you have a field “ad_id”:

I assume that is meant to be “user_id”?

I also notice that, in your query, you have not referenced the owners at all. If you are in fact looking for the results from items linked to branches just by the admins, then you can just remove/ignore the first two subqueries in the following query:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement