php - Joins - get row from one table then get all rows that match in another table? but first table matching row should not be repeated -


i have 2 tables. gallery , joins.

gallery id | title  1 | dog gallery  2 | cat gallery  joins id | gallery_id | picture_id  1 |      1     |     100  2 |      1     |     101  3 |      2     |     56  4 |      1     |     102 

i want id, gallery title gallery - id equal specific id of rows joins gallery id equals specific gallery id.

so above if id 1. want dog gallery gallery , picture_ids 100,101 , 102 joins.

now problem gallery title should comes 1 time. result title=dog gallery picture_id=100,title=dog gallery picture_id=101,title=dog gallery picture_id=102 need result title=dog gallery picture_id=100,picture_id=101 , picture_id=102

you can use group_concat have ids string

select g.*, group_concat(distinct p.picture_id order p.picture_id desc separator ',')  gallery g left join pictures p on p.gallery_id = g.id  group g.id; 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -