I have a Mysql Database and tables with the structure:
- Table 'photos' - ID, Name
- Table 'photos_tags' - Key, Photo_ID, Tag
My goal is to select all photos, which has one tag (it's not a problem) and more tags at once.
I've tried this query, but it's not work
SELECT photos.id FROM photos, photos_tags WHERE photos.id = photos_tags.photo_id AND (tag = 'cute' OR tag = 'cool')
The main problem - this query will select both photos with one of these tags or with two of them. But i need only photos with two these tags at one photo.
Can you help me please? I'm new at MySQL
UPDATE: May be there is a better way to organize this schema? My current realization has 'tags' text-field right in table 'photos'. And I use FIND_IN_SET to make a select. But my table has about 1.5M rows - and some queries are very slow.