Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to concat/append multiple returned rows into only one row?

I have query which returns this result:

+-----------------------------------------+
| product_english                         |
+-----------------------------------------+
| can of orange juice                     |
| oatmeal container                       |
| milk bottle 28 oz                       |
| chocolate powder no sugar added - 16 oz |
| instant coffee 8 oz container           |
| almonds bag 25 oz.                      |
+-----------------------------------------+

it would return 6 rows in total as you can see.

I would like to return all records in only one row. Is that possible?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is the query to visualize things better:

SELECT product_english
FROM menuBreakfast mb
JOIN productPerMenu ppm ON ppm.menu_id = mb.breakfast_id
JOIN productList pL on ppm.product_id = pL.product_id
WHERE breakfast_id = 'B1';

Thanks in advance.

>Solution :

SELECT GROUP_CONCAT(product_english ', ')
FROM menuBreakfast  
WHERE breakfast_id = 'B1';

Also you can apply concat

SELECT concat(product_english ) as product_english FROM menuBreakfast  
WHERE breakfast_id = 'B1'; 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading