0
You have to group by idTema
, sort by the quantity decreasing and limit in 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.
0
2
You have to group by idTema
, sort by the quantity decreasing and limit in 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.
2
I don’t know if it’s the best way to build select but I think it solves.
SELECT idTema FROM nome.tabela GROUP BY idTema ORDER BY count(idTema) DESC LIMIT 1;
Browser other questions tagged mysql select-sql
You are not signed in. Login or sign up in order to post.
But then you’re always filtering 1, right? And if the most used idTema is another id and not 1. Wanted something general, you know?
– Junior Vilas Boas
I’m not limiting the
idTema = 1
is to limit the number of lines that will be returned. ThisSELECT
works pro general.– Roberto de Campos
Got it, I’ll test it.
– Junior Vilas Boas