I have the following query:
SELECT *, RES.res_id 'ID', RES.RES_Title 'Title',
GROUP_CONCAT(DISTINCT T.T_Name separator ', ') 'Topics',
GROUP_CONCAT(DISTINCT CH.CH_Code separator ', ') 'Chapters'
FROM Resources RES
LEFT JOIN topic_to_resource RT ON RT.RT_ResourceID = RES.RES_ID
LEFT JOIN topics T on T.T_ID = RT.RT_TopicID
LEFT JOIN topic_to_chapter TCH on TCH.TCH_TopicID = T.T_ID
LEFT JOIN chapters CH ON CH.CH_ID = TCH.TCH_FrameworkID
WHERE RES_Status = 'Active'
GROUP BY RES.RES_ID
ORDER BY RES_Title ASC, RES_Source DESC LIMIT 0, 10
For each of the GROUP_CONCATs (Topics and Chapters), I need to convert the list into links while keeping the Distinct.
For example, instead of the Topics output of the query above: Sports, Current Events, Politics, Climate, etc.
I need to generate:
<a href="page.asp?topic=Sports" title="Sports">Sports</a>,
<a href="page.asp?topic=Current%20Events" title="Current Events">Current Events</a>,
<a href="page.asp?topic=Politics" title="Politics">Politics</a>,
<a href="page.asp?topic=Climate" title="Climate">Climate</a>
I can achieve the links by nesting a CONCAT within the GROUP_CONCAT, but then I lose the Distinct. Also, I need the query to stay grouped by the Resource ID (RES.RES_ID).
Any ideas on how to accomplish a linked list of distinct topics and chapters?
Many thanks in advance!