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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:36:05+00:00 2026-05-24T20:36:05+00:00

I have a problem with the correct syntax to use UNION and GROUP_CONCAT in

  • 0

I have a problem with the correct syntax to use UNION and GROUP_CONCAT in this situation:

I have 4 tables:

  • base: Is the main table with a lot of columns.
  • mm: Is a mm table that points to the next two tables using a ‘tablenames’ field.
  • t1 and t2 that stores data related.

Records in ‘base’ tables can have many related records in t1 and t2 through the mm table.

I’m creating a VIEW in MySQL and I need all those related records are displayed in a single column separated by commas.

This is the base MySQL code:

SELECT base.uid, t1.nombre_es
FROM base
INNER JOIN mm 
ON mm.uid_local=base.uid
INNER JOIN t1 
ON mm.uid_foreign=t1.uid WHERE mm.tablenames = 't1'

UNION

SELECT base.uid, t2.nombre_es
FROM base
INNER JOIN mm 
ON mm.uid_local=base.uid
INNER JOIN t2
ON mm.uid_foreign=t2.uid WHERE mm.tablenames = 't2'

Thanks in advance.


I could do it using two VIEWS, the first using the code above with the name ‘viewtest”, and the second with this code:

SELECT base.uid,
GROUP_CONCAT(DISTINCT vi.nombre_es ORDER BY vi.nombre_es SEPARATOR ',') as nombre

FROM base

INNER JOIN viewtest as vi
ON vi.uid=base.uid

GROUP BY uid

Now the question is ¿How can I join this two views in a single view?

  • 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-24T20:36:05+00:00Added an answer on May 24, 2026 at 8:36 pm

    You can use derived tables from queries. Next is an example of how you can use them.

    SELECT GROUP_CONCAT( f ) 
    FROM (
      SELECT 1 AS f  # <-- QUERY #1
      UNION 
      SELECT 2 AS f  # <-- QUERY #2
      UNION 
      SELECT 3 AS f  # <-- QUERY #3
    ) AS T
    

    Basically, you can use any SELECT query as an aliased table. Then, you can apply any aggregate functions you need to that aliased query.

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

Sidebar

Related Questions

(I have a problem that I illustrated in this question but had no correct
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a problem and i would like to learn the correct way to
maybe I will not correct explain a problem, maybe somebody help me explain this
I have a two tables A and B I would like to union them
I have a problem that I believe I need to use grouping using xsl:key
I can't get the syntax correct for with static variables and c++ classes. This
Can you please help me with the correct syntax to use when you want
I can only write this in pseudo-code since I don't know the correct syntax..
So basically I have been trying to insert columns into my third table from

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.