Extracting two particular values from a multi valued column I have a table SUBSCRIBER and in it the data is stored in a way that bars is a multi-valued column . Different values of bars are stored in different rows with the ID as following :

ID BARS
1 , BAR1
1 , BAR2
1 , BAR3
2 , BAR4
2 , BAR3
3 , BAR3
4 , BAR1
4 , BAR4


OUTPUT for the data set should be the following:

1,BAR1,
2,,BAR4
3,,,
4,BAR1,BAR4


So the query should be extracting 2 particular BAR values from the multi valued column(BARS) and gives the result for a report based on the conditions as following:

ID,BAR1,BAR4 : WHEN BOTH BAR1 AND BAR4 EXIST
ID,BAR1,, : WHEN BAR1 EXISTS AND BAR4 IS NOT PRESENT
ID,,BAR4 : WHEN BAR4 EXISTS AND BAR1 IS NOT PRESENT
ID,,, : WHEN BOTH BAR1 AND BAR4 ARE NOT PRESENT
If you don't need the extra commas, then:

SELECT CONCAT(id, ',',
          GROUP_CONCAT(bars ORDER BY bars))
    FROM subscriber
    WHERE bars IN ('bar1', 'bar4')
    GROUP BY id;


If you do need the commas, then search for "pivoting".