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 8983741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:54:57+00:00 2026-06-15T20:54:57+00:00

I have three MySQL tables, one with data, one with tags and one with

  • 0

I have three MySQL tables, one with data, one with tags and one with associations between those two, which seems to be common practice when storing tags. The tables look like this:

links:
+----+------------+------------+
| id | url        | added      |
+----+------------+------------+
| 2  | google.com | 2012-12-14 |
| 3  | cnn.com    | 2001-02-13 |
+----+------------+------------+

tags:    
+----+--------+
| id | tag    |
+----+--------+
| 1  | search |
| 2  | news   |
+----+--------+


taglink:
+----+--------+-------+
| id | linkid | tagid |
+----+--------+-------+
| 1  | 2      | 1     |
| 2  | 3      | 1     |
| 3  | 3      | 2     |
+----+--------+-------+

What I want to receive is the following table:

+----+------------+------------+--------+-------------+
| id | url        | added      | tagids | tags        |
+----+------------+------------+--------+-------------+
| 2  | google.com | 2012-12-14 | 1      | search      |
| 3  | cnn.com    | 2001-02-13 | 1,2    | search,news |
+----+------------+------------+--------+-------------+

To do so I had this query:

select 
   links.*,
   group_concat(taglink.id) as tagids,
   group_concat(tags.tag) as tags
from links
   join taglink on taglink.linkid=links.id
   join tags on tags.id=taglink.tagid

but this gives me a single row with every tag used, like so:

+----+------------+------------+--------+-------------+
| id | url        | addad      | tagids | tags        |
+----+------------+------------+--------+-------------+
| 2  | google.com | 2012-12-14 | 1,2    | search,news |
+----+------------+------------+--------+-------------+

Everything seems to be grouped, which is not what I was looking for. Does anybody know the solution?

  • 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-15T20:54:58+00:00Added an answer on June 15, 2026 at 8:54 pm

    You need to use GROUP BY with your group_concat functions as follows, or they’ll behave unpredictably. Try this.

        select links.id, links.url, links.added,
               group_concat(tags.id ORDER BY tags.id) as tagids,
               group_concat(tags.tag ORDER BY tags.id) as tags
          from links
          join taglink on taglink.linkid=links.id
          join tags on tags.id=taglink.tagid
      group by links.id, links.url, links.added
      order by links.id
    

    Note that I’ve added some ORDER BY items to make the order of things predictable.

    Go fiddle: http://sqlfiddle.com/#!2/2b3b9/5/0

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

Sidebar

Related Questions

I have two MySQL tables describing data that can be extended into subclasses, one
I have a MySQL query that: gets data from three tables linked by unique
I have three tables, table one (tableA) containing users data like name and email,
I have a complex MySQL query that joins three tables and self-joins one table
I am using PHP and MySQL. I have two tables, one for customers, and
i have three tables, i want to select all data from one of the
I have an issue getting data from three tables, which I want to return
I have two tables, one is 'tags' that stores tid (auto increment) and name
Basically, I have three tables workplaces with a field id (the one of which
I have three mysql tables items =========== id title items_in_categories ============================ id item_id category_id

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.