Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:13:32+00:00 2026-06-09T13:13:32+00:00

My question is pretty similar to MySQL: is it possible to group_concat multiple rows?

  • 0

My question is pretty similar to MySQL: is it possible to group_concat multiple rows?, but I can’t get my head around how the group concat is working.

My actual dataset would be hard to explain – I’ll use a simplified set of tables and relationships as an example.

say i have a table photos

id  filename
1   bob.jpg
2.  ken.png
3.  lisa.jpg
4.  jim.jpg
...

and a table tags

id  title
1   family
2   friends
3   school
4   california
...

and a bridge called photo_tags

photo  tag
1      2
1      3
1      4
2      1
3      1

and i want back rows like this:

photo_id  filename   tags
1         bob.jpg    2,3,4
2         ken.png    1
3         lisa.jpg   1
4         jim.jpg    (NULL)

or…

photo_id  filename   tags
1         bob.jpg    friends,school,california
2         ken.png    family
3         lisa.jpg   family
4         jim.jpg    (NULL)

My initial guess was something like this:

SELECT photos.filename,
GROUP_CONCAT(photo_tags.tag) AS associated_tags
FROM photos
LEFT OUTER JOIN tags
ON tags.photo = photos.id
GROUP BY photo_tags.tag

But (probably obvious to someone who knows what they’re doing), that didn’t work. After doing some research, and referencing the link above, I tried various permutations of this:

SELECT 
  file_name,
  GROUP_CONCAT(photo_tag_ids) AS associated_tags
FROM (
  SELECT 
    photos.filename AS file_name,
    photo_tags.tag AS photo_tag_ids
  FROM  
    photos
    INNER JOIN photo_tags
         ON photo_tags.photo= photos.id
) whatever
GROUP BY file_name
ORDER BY file_name;

TYIA.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:13:33+00:00Added an answer on June 9, 2026 at 1:13 pm
    SELECT photos.filename,
           GROUP_CONCAT(photo_tags.tag) AS associated_tags
    FROM photos
    LEFT OUTER JOIN tags ON tags.photo = photos.id
    GROUP BY photos.filename
    

    You have to group by a column that will be unique for every row and in the group you can build a group_concat of other columns. So change your group by to photos.filename.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty sure there's similar question around here, but I can't find it. Suppose
My question is pretty similar to that except but I need only the header
This question is pretty much similar to this one , but for SQL Server
I asked a pretty similar question a few days ago, but this one is
Although this is pretty basic, I can't find a similar question, so please link
The title of the question pretty much states the problem. Is it possible?
My question is pretty simple, but I am having a hard time finding any
Stumped here. Posted a similar question before. We have a pretty large WPF app
The title pretty much precisely asks the question, but I shall repeat; When I
My question is pretty simple, but I am having a bad time finding a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.