sql >> Base de Datos >  >> RDS >> Mysql

MySQL:SELECT y COUNT en la misma consulta

Algo como esto:-

SELECT city.id, city.name, city.slug, COUNT(club.id) AS club_count
FROM city
INNER JOIN club
ON city.id = club.city_id
WHERE club.published = 1
GROUP BY city.id, city.name, city.slug
HAVING club_count > 0