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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:47:06+00:00 2026-06-15T11:47:06+00:00

I have 2 table in the database: mainTable and classificationTable: mainTable: id | classification_id

  • 0

I have 2 table in the database: mainTable and classificationTable:

mainTable:

id  |   classification_id   |   name
---------------------------------------
1   |           1           |   Name1
2   |           2,3,4       |   Name2
3   |           1,4         |   Name3
4   |           4           |   Name4

classificationTable:

classification_id   |   class_name
---------------------------------------
        1           |   Class Name1
        2           |   Class Name2
        3           |   Class Name3
        4           |   Class Name4

I want to get a select for example for row with ID 3 from mainTable like:

id          =   3
class_name  =   Class Name1, Class Name4
Name        =   Name3

I try this select, but this return only first elemnt from array (fore exempla for row with ID 3, this return only Class Name1)

SELECT i.*, 
(SELECT GROUP_CONCAT(cl.class_name) FROM classificationTable as cl WHERE cl.classification_id IN(i.classification_id)) as class_name 
FROM mainTable as i;

Help PLZ.

  • 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-15T11:47:08+00:00Added an answer on June 15, 2026 at 11:47 am

    Yes, you have a poorly designed database. But you can do what you want.

    This requires two steps. The first is to join the mainTable to the classificationTable by looking for each classification_id in the list in the mainTable. You can do this using the like operator.

    The second step is to bring all the class names back into one column. This is handled using group_concat.

    The following query accomplishes this (although it is not tested, so it might have a typo):

    select mt.id, mt.name, group_concat(ct.class_name separator ', ')
    from mainTable mt join
         classificationTable ct
         on concat(',', classification_id, ',') like concat('%,', ct.classification_id, ',%')
    group by mt.id, mt.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table with some rows that I want to fetch using
I have a database table named Categories . I want to create a form
I have one main table MainTable ( ID, Name ) The Name column contains
i have database table like this +-------+--------------+----------+ | id | ip | date |
My database table have a Timestamp column named as inTime and i am using
i have a database table of website links. i have another table of tags,
I have a table in database that is having some fields one of which
that my problem: I have database table like that: id (AI) market_id 1 6
I have a database table containing dates (`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00').
I have a database table, my goal is to read in each of the

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.