Mysql/php - Query Question -


i have been trying figure out different way complete task on question on website, think maybe making difficult.

here have: table with, , imageid, imagename, galleryid table comments, author, date, imageid

what want do query find of images have galleryid=42. in addition, grab of comments associated each picture (via imageid) , concatenate them in single value. example:

imageid: 1234, imagename: img425, galleryid: 42, comments: cool!|||john smith|||2010-09-06~~nice shot!|||richard clark|||2010-10-01~~i remember run.|||susan edwards|||2010-10-04

i need concatenate of results comments table each image , put them in single value, can parse them via php in body of page.

group_concat() way go, , other answers close. kiss.

select    imageid, imagename, galleryid    , group_concat(       concat_ws('|||', comment.author, comment.date, comment.content)       separator '~~'    ) comments    images    join galleries using (galleryid)    join comments using (imageid)    galleryid = 42 group    imageid, imagename, galleryid 

note group_concat() has short max length default. may have run

set group_concat_max_len = 65535; 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -