get a list of all commentsYou are referring to getting all comment records to generate the average - not actually return the comments themselves?

Assume the above is correct then you could try this

```
SELECT *, 6371.04 * acos( cos( pi( ) /2 - radians( 90 - latitude) ) * cos( pi( ) /2 - radians( 90 - '$lat' ) ) * cos( radians( longitude) - radians( '$lon' ) ) + sin( pi( ) /2 - radians( 90 - latitude) ) * sin( pi( ) /2 - radians( 90 - '$lat' ) ) ) AS distance, a.average_rating
FROM cms_salon s LEFT JOIN (SELECT AVG(rating) AS average_rating, salon_id FROM comments GROUP BY salon_id) a on a.salon_id = s.salon_id
GROUP BY s.salon_id HAVING distance < '$radius' ORDER BY distance ASC
```