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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:39:00+00:00 2026-05-29T22:39:00+00:00

I have a problem. I have the following tables in MySQL: +———+ +———–+ +———+

  • 0

I have a problem. I have the following tables in MySQL:

+---------+    +-----------+   +---------+
| USER    |    | USER_LANG |   | LANG    |
| id_user |    | id_user   |   | id_lang |
| name    |    | id_lang   |   | name    |
|         |    | years     |   |         |
+---------+    +-----------+   +---------+

and I have the following information:

+--------------------------------+
| ID_USER |  ID_LANG   |  YEARS  |
|    1    |      5     |     1   |
|    1    |      6     |     2   |
|    2    |      5     |     9   |
|    2    |      6     |     3   |
|    3    |      5     |     7   |
+--------------------------------+

What I need to achieve is to group all users who speak exactly the same group of languages ​​and sum the years. For example, I need to get is:

+----------------------+
| LANGS   |  SUM_YEARS |
|   5;6   |      15    |
|    5    |      7     |
+----------------------+

It is very strange, but I need this. I tried with GROUP_CONCAT but didn’t work.

Hopefully they can help me.

Thanks in advance.

  • 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-29T22:39:02+00:00Added an answer on May 29, 2026 at 10:39 pm

    That’s an unusual request, but it should work out with the GROUP_CONCAT() inside a subquery:

    /* Outer query groups the concatentated langs and sums years */
    SELECT 
      LANGS,
      SUM(YEARS) AS TOTAL_YEARS,
      /* Edit: bonus list of users speaking the languages */
      GROUP_CONCAT(ID_USER) AS USER_GROUP
    FROM (
       /* Subquery gets group concat of languages & sum per user */
       SELECT
         ID_USER,
         GROUP_CONCAT(ID_LANG) AS LANGS,
         SUM(YEARS) AS YEARS
       FROM USER_LANG
       GROUP BY ID_USER
    ) USER_SUB
    GROUP BY LANGS
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following problem: I have two tables: (simplified) +--------+ +-----------+ | User
I'm having the following problem with 2 MySQL tables that have a relation: I
I'm new to PHP, HTML and MySQL, and have encountered the following problem: I
I have the following problem. I have 2 tables in the database - table1
I have a problem formulating a MySQL query to do the following task, although
In one of my MySQL tables, I have following columns: Skills varchar(80) Industry varchar(40)
I have the following problem: I want to compare two tables and see if
I have the following tables in MySQL: users profile rates In the users table,
I have the following mysql tables: CREATE TABLE `video` ( `video_id` int(11) unsigned NOT
I have the 3 following tables in a MySQL 4.x DB : hosts: (300.000

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.