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

  • Home
  • SEARCH
  • 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 7807167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:46:04+00:00 2026-06-02T02:46:04+00:00

So I need to select distinct values from one table, but join all the

  • 0

So I need to select distinct values from one table, but join all the related values from another table but within the same query.

Basically I’m following the Toxi TagSystem Schema http://forge.mysql.com/wiki/TagSchema#Toxi

Three-table many-to-many mapping between.

And I need to show all the inserted values (docs) one on each row, but one of the columns I would like to have all the tags that the file has separated by a comma for example.

For now I have

SELECT 
    docs.id AS id, 
    docs.orig_file AS orig_file, 
    docs.date_sent AS date_sent, 
    tags.tag_name AS alltags
FROM documat AS docs
LEFT JOIN documat_file2tag AS f2t ON f2t.doc_id = docs.id
LEFT JOIN documat_tags AS tags ON tags.id = f2t.tag_id

But this is repeating the rows if a specific docs.id has more than a tag. The final result I would like to have on each row is:

| ID | orig_file | date_sent | alltags |

With the desired result example:

| X | example_value.pdf | 2012-03-23 10:14:05 | tag_ex_1, tag_ex_2, etc |
  • 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-02T02:46:06+00:00Added an answer on June 2, 2026 at 2:46 am

    Group Concat:

    SELECT 
        docs.id AS id, 
        docs.orig_file AS orig_file, 
        docs.date_sent AS date_sent, 
        GROUP_CONCAT(distinct tags.tag_name) AS alltags
    FROM documat AS docs
    LEFT JOIN documat_file2tag AS f2t ON f2t.doc_id = docs.id
    LEFT JOIN documat_tags AS tags ON tags.id = f2t.tag_id
    GROUP BY docs.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to select data from one table and insert it into another table.
I need help with a query to get distinct records from the table. SELECT
I need to select all columns from two tables, but need to be able
My problem is this: I need to select values from groups table that do
I need to select multiple records I use SELECT * FROM `table` WHERE `ID`
I need to select rows randomly from an Oracle DB. Ex: Assume a table
I need to select a field called ProgramID from a table and if the
I need to select multiple table and one of it is transposed, my table
I need some help with the design of a query. I've got one table
I need to gather Distinct Id's from a particular table using LINQ. The catch

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.