Skip to content
Advertisement

Get records in Many to Many query

I have three tables: 1.article – 2.tag – 3.article_has_tags (An article may have many tags).

article:

tag:

article_has_tags: (it contents article & tag primary keys)

I need to return the first three articles with all their tags.

My query is:

But obviously it’s returning:

The result I need is something like this:

How can I get the result I need? Thank you.

Advertisement

Answer

you can use group_concat in MySQL. Here is the demo.

Output:

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