MYSQL Sub Query (SELECT MIN)

1

I have this code, but what I want is SELECT MIN of "n_reminders" and only just the min number. I wanted the club with fewer rowers. Help? :)

SELECT (clube.nome) AS clube,
       COUNT(remadores.cod_remador) AS n_remadores
FROM clube,
     remadores
WHERE clube.cod_clube=remadores.cod_clube
GROUP BY clube.nome
HAVING COUNT(remadores.cod_remador) >= ALL
  (SELECT COUNT(remadores.cod_remador) AS n_remadores
   FROM clube,
        remadores
   WHERE clube.cod_clube= remadores.cod_clube
   GROUP BY remadores.nome)
    
asked by anonymous 09.01.2018 / 16:31

1 answer

0

Use temporary tables.

SELECT min(cod_remador) FROM
(SELECT (clube.nome) AS clube,
       COUNT(remadores.cod_remador) AS n_remadores
FROM clube,
     remadores
WHERE clube.cod_clube=remadores.cod_clube
GROUP BY clube.nome
HAVING COUNT(remadores.cod_remador) >= ALL
  (SELECT COUNT(remadores.cod_remador) AS n_remadores
    FROM clube,
        remadores
   WHERE clube.cod_clube= remadores.cod_clube
   GROUP BY remadores.nome)) AS Temp
    
17.01.2018 / 01:05