Sunday, 11 August 2013

MYSQL selection from tables

MYSQL selection from tables

Hi i have client wich can have a project wich project can have galleries
wich galleries have a imgs. So i create a tables: clients, projects,
galleries, images in every table i have idetifier in projects - client_id,
galleries - project_id, images - gallery_id. I want to select all projects
and galleries with all images for specific client. The problem is that i
want to separate the galleries. That i can switch in the front end the
galleries with buttons.
This is the full query but how to seperate each gallery with the result.
SELECT im.image_name, im.gid, ga.gallery_name FROM images` AS im,
`gallerys` AS ga , `projects` AS pr WHERE pr.id = ga.project_id AND
ga.id = im.gid AND pr.id=$id
Thanks guys this is the solutions of the task:
SELECT group_concat( im.image_name ) , im.gid, ga.gallery_name
FROM `gl_images` AS im
JOIN `gl_gallerys` AS ga ON ga.id = im.gid
JOIN `gl_projects` AS pr ON pr.id = ga.project_id
WHERE pr.cid =43
GROUP BY ga.id
It is combined from the answers of Joe Minichino and Gordon :) Thanks alot :)

No comments:

Post a Comment