MySQL query join table dengan count dan group by


Setelah nyoba berbagai query, akhirnya untuk melakukan query mysql dengan dua tabel dimana salah satunya menggunakan query count dan group by saya mengeksekusi perintah berikut:

select tb1.*, tb2.totdata
from t_satu tb1
left join (SELECT data_id, count(data_id) as totdata FROM t_dua group by data_id order by totdata desc LIMIT 7) tb2 on tb1.data_id = tb2.data_id
order by tb2.totdata desc limit 7

Nah, silahkan dicoba.


You May Also Like

About the Author: rasupe

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *