mercredi 13 juillet 2016

mysql assign variables on multiple rows in select statement

i have this sql query

SELECT DISTINCT category.title, category.id FROM category 
INNER JOIN request ON category.id = request.category_id;

+---------------+----+
| title         | id |
+---------------+----+
| Clothing      |  4 |
| Dance         | 12 |
| Entertainment | 37 |
+---------------+----+

how can i fetch all the result rows of this query as a text in another table like:

update message set description = "category : <title>, id: <id>,";

select description from message;

+-------------------------------------------------------------------------------------+
| description        
+-------------------------------------------------------------------------------------+
| category : Clothing, id:  4, category : Dance id: 12 category : Entertainment id: 37|
+-------------------------------------------------------------------------------------+

i'd like to perform this using a stored procedure, but i'm a newbie on this. thnks for your time.

Aucun commentaire:

Enregistrer un commentaire