2

Is there a function in mysql that would return all items in just one row?

EXAMPLE:

Table: | id | name | ------------- | 1 | john | | 2 | mike | | 3 | jane | 

Query:

SELECT concat_name(name) FROM tbl_name 

concat_name as the function.

Expected Result:

| name | ------------------- | john, mike, jane| 
0

2 Answers 2

4

Use group_concat():

select group_concat(name order by id separator ',') as name from table; 
Sign up to request clarification or add additional context in comments.

Comments

0

Use GROUP_CONCAT FUNCTION

http://dev.mysql.com/tech-resources/articles/4.1/grab-bag.html

SELEct m.meal_Id, GROUP_CONCAT(dish_id) dish_ids, GROUP_CONCAT(dish_name) dish_names FROM DISH_HAS_DISHES m JOIN DISH d ON (m.dish_id = d.dish_id) GROUP BY meal_Id 

2 Comments

Thanks @Harshil for formatting ans. I had given ans from mobile phone so I was not able to format.
No worries. BTW the link mentioned in your answer is not redirecting to documentation.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.