Select group_concat(ID SEPARATOR '|')
from TableJ J
Left Join TableL L on L.J_ID=J.ID
Left Join TableB B on B.LJ_ID=L.F_ID
Left Join TableLJ LJ on LJ.ID=L.F_ID
Group
by J.ID
The output returns records like
- 103237|43775|84462|19153|54618|108646|50142|96946|37251|75984|54524
- 29728|46758|65987|20772|34513|61323|2778|32630|53616|103450|27152|37278|65950|13837|33500|59490
etc
The issue is I need to limit the # of records/pipes in the results to 5 records.
In TableLJ there is a field Population
which I can use to sort and limit but no amount of fiddling allows me to specify I want to Select the top 5 from that table PER group.
Update is that I can do the following to limit the group_concat (still does not solve getting them sorted first by LJ.Population)
substring_index(group_concat(ID SEPARATOR '|'),'|',5)