mysql - Select related Elements Attributes as String -
i have items table , tags table. have 1 select gets items under condition , each item selects related tags , puts them in string become seperate field.
example:
table_items: id | title --------------------------- 01 | peter --------------------------- 02 | john --------------------------- 03 | cindy tags: id | title --------------------------- 01 | tall --------------------------- 02 | tiny --------------------------- 03 | blone --------------------------- 04 | loud --------------------------- 05 | ... tags_to_items: itemid | tagid --------------------------- 01 | 02 --------------------------- 01 | 04 --------------------------- 02 | 01 ...
i think point.
now want result this: itemid | title | tags --------------------------- 01 | peter | tiny, loud --------------------------- 01 | john | tall, fast, bored
can mysql? how?
in mysql, need group_concat
function that.
something like:
select ti.id, ti.title, group_concat(t.title) table_items ti inner join tag_to_items tti on (ti.id = tti.itemid) inner join tags t on (t.id = tti.tagid) group ti.id, ti.title
Comments
Post a Comment