I would like to make a SELECT
where you would select the foreign key ( idTema ) most used
Example:
That example above would be 1
How would that SELECT
?
I do not know if it's the best way to build the select but I think it works.
SELECT idTema FROM nome.tabela GROUP BY idTema ORDER BY count(idTema) DESC LIMIT 1;
You have to group by idTema
, sort by quantity in descending order and limit by 1 record:
SELECT a.'idTema', COUNT(*) qtde
FROM nome_da_tabela a
GROUP BY a.'idTema'
ORDER BY qtde DESC
LIMIT 1;
See more about GROUP BY
here .