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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:04:27+00:00 2026-05-21T02:04:27+00:00

In a previous question I was told that if I want to store multiple

  • 0

In a previous question I was told that if I want to store multiple languages for a user then it is best to have a separate table mapping languages and users together.
That makes sense because it is a classic many-to-many relationship so that is what I have done.

My question now is what query can I write that will concatenate all the language names for each user and then display that as a table?

I made the following (is it correct?):

CREATE TABLE language (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name char(20) NOT NULL UNIQUE)

CREATE TABLE user (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name char(20) NOT NULL UNIQUE)

CREATE TABLE user_language (
id_user INT REFERENCES user(id),
id_lang INT REFERENCES language(id) )

I then inserted 3 test users, 7 test languages and inserted 9 pairs into the user_language table. Now I want to print a concatenated list of the languages each user speaks next to the users names using only one MySQL query and I have no idea how to do that.
So for example I would like to see

User    |   Languages
--------|---------------
Bob     | English, French
Alex    | Spanish, Portuguese
Ivan    | Russian, English, German 

Any ideas? Am I even on the right track?

EDIT

I am aware of the JOIN function so printing the list out as a set of individual pairs is not my intention. I specifically want to concatenate the languages for each user without resorting to writing a loop in a script (it would be in PHP in my case).
I thought there might be some way of writing a subquery and using the CONCATENATE function that might be able to help me…? Am I way off?

  • 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-05-21T02:04:27+00:00Added an answer on May 21, 2026 at 2:04 am

    You’ll want to take a look at using an INNER JOIN for this. Essentially, the JOIN is going to take a look at the IDs in each field and then match data together for entries that have matching IDs.

    Consider the following SQL query:

    SELECT user.*, language.name FROM user
    INNER JOIN user_language ON user.id = user_language.id_user
    INNER JOIN language ON user_language.id_lang = language.id;
    

    Order of the INNER JOINs is important; the first thing we need to do is be able to reference language IDs relative to the user ID. The first INNER JOIN is going to give each user a list of language IDs which the user can speak. The second is going to map that language ID that was assigned to the user to a name.

    However, the above will not return them in a comma-separated list. Instead, you’ll get something like this:

    name    |    language
    -------------------------
    bob     |   English
    bob     |   Dutch
    Sally   |   English
    Sally   |   Spanish
    Sally   |   German
    

    You’ll have to do some post processing to put the data into a comma-separated list. Doing so in almost any language should be fairly straightforward.

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

Sidebar

Related Questions

I was told in a previous question that my query is prone to SQL
I asked a previous question about mapping an enumerated value on a table using
In my previous question ( here ), I was told I have to redirect
I was told in a previous question that there can be issues when using
In previous question of mine, someone had meantioned that using Semaphores were expensive in
This question is related to a previous question of mine That's my current code
This question follows on from a previous question, that has raised a further issue.
This question is related to my previous question . The storyline: I have an
Continuing from my previous question , is there a comprehensive document that lists all
In a previous question I was told how to rewrite my computation expressions so

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.