Skip to content
Advertisement

Get all values from intermediate table

I have a mySQL three-table many-to-many setup with link table, simplified here:

I need to return all entries for a given category name but I want to include a list of all the categories a given entry is attached to. For example, if a search is for Addictions and the entry is also listed in categories Mental health and Young people, I want an output field for each result with all three categories listed.

How do I do this?

Advertisement

Answer

You need direct lookup for to get the list of entries, and backward lookup for to get categories list for each entry. Backward lookup must use another tables copies.

If you need the same for more than one category (maybe even all) then

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement