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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:10:37+00:00 2026-05-16T18:10:37+00:00

Have two tables with a linking table between them. USERS +——-+———+ | userID| Username|

  • 0

Have two tables with a linking table between them.


USERS
+-------+---------+
| userID| Username|
+-------+---------+
|     1 |  Nate   | 
|     2 |  Nic    | 
|     3 |  John   | 
+-------+---------+

SITES
+--------+---------+
| siteID | Site    |
+--------+---------+
|     1  |  art    | 
|     2  |  com    | 
|     3  |  web    | 
+--------+---------+

USER_SITES
+-------------+---------+---------+
| user_site_id| user_id | site_id |
+-------------+---------+---------+
|     1       |  1      | 1       |
|     2       |  1      | 2       |
|     3       |  1      | 3       |
|     4       |  2      | 2       |
|     5       |  2      | 3       |
+-------------+---------+---------+

I want to do one query that will output like this


USERS
+---------+----------------+
| username| sites          |
+---------+----------------+
|  Nate   |  art, com, web | 
|  Nic    |  com, web      | 
+---------+----------------+

Can that be done easily with one query?
I would like to be able to do that in MySQL, and POSTgreSQL – but I’ll take whatever I can get!

  • 1 1 Answer
  • 1 View
  • 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-05-16T18:10:38+00:00Added an answer on May 16, 2026 at 6:10 pm

    It can be done in MySQL using GROUP_CONCAT:

    SELECT
        username,
        GROUP_CONCAT(Site ORDER BY Site SEPARATOR ', ') AS sites
    FROM USER_SITES
    JOIN USERS ON USER_SITES.user_id = USERS.userID
    JOIN SITES ON USER_SITES.site_id = SITES.siteID
    GROUP BY username
    

    Result:

    +---------------------------+
    | username  | sites         |
    +---------------------------+
    | Nate      | art, com, web |
    | Nic       | com, web      |
    +---------------------------+
    

    To see how to emulate GROUP_CONCAT in PostgreSQL see this question:

    • Postgresql GROUP_CONCAT equivalent?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two items, users and posts, and a join table linking them together.
I have two tables with a linking table describing their many-to-many relationship. TABLE buildings
I have a database two tables and a linking table that I need a
I have two tables, a user table and a application table: User id username
I have two tables(entries and tags) with a many-to-many linking table. Right now, I'm
I have many-to-many linking table between two entities, datacenters and projects, in legacy code.
I have two tables: tags and linking table photos_tags. I want to add a
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |

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.