0

I have 3 tables like this:

Areas 
id      city_id         area
1       1               mayfield
2       2               cleveland

neighbourhood
id      neighbourhood   area_id
101     cayahoga        1
102     milan           1
103     downtown        2

Salons
id      neighbourhood_id
3       101
4       101
5       102

I am trying to get count of all Salons in all areas.

Like salons in areas (mayfield = 2, cleveland = 1)

Is it possible to do this in 1 query?

2 Answers 2

1
SELECT areas.area,COUNT(Salons.id)
FROM areas
LEFT JOIN neighbourhood ON neighbourhood.area_id = areas.id
LEFT JOIN Salons ON Salons.neighbourhood_id = neighbourhood.id
GROUP BY areas.id
Sign up to request clarification or add additional context in comments.

Comments

1
select area,count(s.id) as salon_count FROM
Areas a
INNER JOIN neighbourhood n
ON a.id = n.area_id
INNER JOIN
Salons s on s.neigbourhood_id = n.id
GROUP BY area

2 Comments

not giving count like: mayfield 2, cleveland 1. It is just giving count = 3?
Not sure why that wouldn't work. I've just changed it to "count(s.id)"... Should work now...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.