Hi All,
Can somebody please help me with this.. I just cannot get my head around it:
I am cleaning up some old code in a website I build years ago. So please do not mind the colum names. They will eventually be adapted too, I suppose.
I have three tables:
w_images (Id, Name)
w_imgtotheme (ImgNr, ThemeNr)
w_theme (Id, Themes)
This effectively create the option to have many-to-many relations: Each image can belong to each theme, and each theme can be linked to each image.
How I want to select images & themes from these tables. THis is easy enough with a join syntax. But when I start adding conditions to the statement, it fails. I am sure there is somwething wrong with the join type, but do not know what:
This
SELECT * FROM w_images
inner join w_imgtotheme
on w_images.Id = ImgNr
inner join w_theme
on w_theme.Id = ThemeNr
ORDER BY w_images.Id
results in: Showing rows 0 - 29 (431 total)
Which is expected, with 181 images, and a number of themes per image.
However, this:
SELECT *
FROM w_images
inner join w_imgtotheme
on w_images.Id = ImgNr
inner join w_theme
on w_theme.Id = ThemeNr
where Themes = 'Landmarks'
and Themes = 'Buildings'
gives me 0 results. This is because it thinks there cannot be this option. I know there are images which belong to both Landmarks and Buildings. How do I change the query so that it will retrieve all the combinations?
So:
img1, Themes: Landmarks, buildings, human
img2, Themes: Buildings, Human
Query: select ... Themes = Landmarks
Output:
Img1 - Landmarks
Img1 - Buildings
Img1 - human
Hope this is clear enough. Let me know if you need more info.
J.