select - Joining MySQL tables in a tricky way -


i have 3 tables

table persons

id | name 

table files

id | person_data | person_id 

table items

id | item_name | file_id 

each person has multiple files , each file has multiple items. there way select each person it's items using mysql returning this:

person - file_id -> item 1, file_id -> item 2, file_id -> item 3 

i thinking on type of join, tried combinations imagine think join it's not solution, or...

use group_concat.please check sqlfiddle

select   b.id,b.name,   group_concat(b.items separator '|') (select         p.id,p.name,         concat(f.id,' -> ', group_concat(i.item_name)) items       persons p,         files f,         items       p.id = f.person_id           , f.id = i.file_id       group f.id) b group b.id 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -