Im trying to get all the posts and all of their images in order of index separated by a comma. So the idx could be 0,1, or 2 meaning a post can have up to three pictures.
My tables are Posts and Post_Pictures
Post
postId: (PRIMARY KEY)
fullName: (VARCHAR)
Post_Pictures
postPictureId (PRIMARY KEY)
image (STRING)
idx (INT)
post_id (FOREIGN KEY)
The final query should look like this for images belonging to the same postId:
postId | fullName | imagesInOrder |
1 Sam (Img Url), (Img Url), (Img Url)
This is my current query which returns only ONE post instead of all of them and puts every image concatenated into one column instead of only the images that belong to that post:
SELECT p.*, GROUP_CONCAT(pp.image SEPARATOR ',') as photos FROM Posts as p LEFT JOIN Post_Pictures as pp ON p.postId
= pp.post_id
;