[SOLVED] MySQL: Get DISTINCT values of repeated values and GROUP CONCAT of non-repeating values which are part of the same table


I have this table:
enter image description here
I want to get results something like this:
enter image description here

If you note,

  1. I require the id of the first record which matches the condition. For example, ID 6 & 8 are the first record of SH001 – S2 & SH002 – S1, respectively.
  2. Plus values in ‘day’ should be of proper sequence as shown & not like ‘Fri,Mon,Thu’.

I tried some queries but it was not giving me the intended results. So can anyone help me in the same.


SELECT MIN(id), show_id, show_name, season_id, GROUP_CONCAT(day)
FROM table
GROUP BY 2,3,4

Answered By – Akina

Answer Checked By – Candace Johnson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *