So i have a database with a few tables. the main is Plant. I also have a PlantEffects table that has plant_id, effect_id. What I need to do select Plants but with the top 5 PlantEffects by count on PlantEffects.effect_id. So it would come out as
|ID|NAME|top_effect_ids|
|1 |abc |1,4,5,6,7 |
|2 |def |3,2,9,7,5 |
If I understand your question correctly, you want to get the top five
effect_ids (by count) into a CSV list.You can do something like this: