How to display categories that have records?

0 like 0 dislike
5 views
Hello !
I have two signs in the database, a List of Categories and Records. The table Entries store the id of the selected Category when you publish.
Faced with this challenge, I want to display on the list page, where such information:
Category(if it has at least one record), and under it the last 5 records.
And so to each other.

Tell me how this in Yii2 to organize.
Thanks in advance.
by | 5 views

1 Answer

0 like 0 dislike
SELECT c.category_id, COUNT(r.record_id) AS records FROM category AS c LEFT JOIN records AS r USING(record_id) GROUP BY c.record_id HAVING records > 5
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Apr 25, 2019 by dmitrylee
110,608 questions
257,186 answers
0 comments
33,853 users