0

I have select table like this

SELECT COUNT(id_lokasi) AS terbanyak, id_lokasi 
FROM personil_tunas_paragitas 
GROUP BY id_lokasi ORDER BY terbanyak DESC LIMIT 1

then i want to select the id_lokasi

SELECT id_lokasi 
FROM (SELECT COUNT(id_lokasi) AS terbanyak, id_lokasi 
FROM personil_tunas_paragitas GROUP BY id_lokasi ORDER BY terbanyak DESC LIMIT 1);

but this query give me error. am i have something wrong with this query?

  • 2
    `Am I have something wrong with this query?` , yes . [every derived table must have alias](https://www.google.com/search?q=every+derived+table+must+have+alias&rlz=1C1CHZN_enAL978AL978&oq=every+derive&aqs=chrome.0.0i512j69i57j0i390l5.3392j0j7&sourceid=chrome&ie=UTF-8) – Ergest Basha Dec 27 '22 at 15:23
  • https://stackoverflow.com/questions/1888779/what-is-the-error-every-derived-table-must-have-its-own-alias-in-mysql – Ergest Basha Dec 27 '22 at 15:26
  • Why are you selecting the count if you don't want to return it? You can write `SELECT id_lokasi FROM personil_tunas_paragitas GROUP BY id_lokasi ORDER BY COUNT(id_lokasi) DESC LIMIT 1` – Barmar Dec 27 '22 at 16:18

0 Answers0