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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:04:53+00:00 2026-06-14T08:04:53+00:00

In mysql i need to get enum fields side by side in a column

  • 0

In mysql i need to get enum fields side by side in a column when i run a query with group by , just like as follows.

There is table as like below

mysql> describe tabex;
+---------+----------------------------+------+-----+---------+----------------+
| Field   | Type                       | Null | Key | Default | Extra          |
+---------+----------------------------+------+-----+---------+----------------+
| id      | int(11)                    | NO   | PRI | NULL    | auto_increment |
| personid| int(11)                    | YES  |     | NULL    |                |
| color   | enum('red','blue','white') | YES  |     | NULL    |                |
+---------+----------------------------+------+-----+---------+----------------+

there are different shirts , the column personid describes the that person id and color indicates the color of his shirt..

the data in table is as follows

mysql> select * from tabex;
+----+----------+-------+
| id | personid | color |
+----+----------+-------+
|  1 |        1 | red   |
|  2 |        1 | white |
|  3 |        2 | blue  |
|  4 |        2 | red   |
+----+----------+-------+
4 rows in set (0.00 sec)

when i ran a query i am getting results like this

mysql> select personid , color from tabex group by personid;
+----------+-------+
| personid | color |
+----------+-------+
|        1 | red   |
|        2 | blue  |
+----------+-------+

but i want the result like below

+----------+-------------+               
|personid  |   color     |               
+----------+-------------+               
|1         |   red,white |               
|2         |   blue,red  |               
|          |             |               
+----------+-------------+  

how can i get the result as above by using group by and aggregation (if any for enum).

that is here i want to get the result for enum fields as like we will get by using count or sum functions and group by .

  • 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-14T08:04:54+00:00Added an answer on June 14, 2026 at 8:04 am

    The GROUP_CONCAT() aggregate function does what you want:

    SELECT personid, GROUP_CONCAT(color) colors
    FROM tabex
    GROUP BY personid
    

    This works with any kind of field, not just ENUM.

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

Sidebar

Related Questions

I need some help optimizing a MySQL query or table When I run this
In a mysql table for a date column(login_time), i need to get the logins
I have a mySQL query to get columns from a table like this: String
Mysql: i need to get the offset of a item in a query. I
Often I just need to get a single value from MySQL that I know
I need to get the closest date to current date from a MySQL table.
I have a mysql table and I need to get random row and get
I have a big MySQL users table and need to get six random rows
I need to get the last inserted id of table that have multi-column primary
I'm just getting started with MySql and need to run simple queries on 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.