List:General Discussion« Previous MessageNext Message »
From:Jens Kleikamp Date:November 9 2006 12:07pm
Subject: mysql query question (images,tags)
View as plain text  
hi to all,

I have a simple question/szenario.

Here are my tables:

1. image (id, name)
2. tag (id, name)
3. images_tags (image_id, tag_id)

At the moment I have the following working query, it selects all images 
which have *at least one of the tag ids* (25,30) assigned.

SELECT DISTINCT image.id, image.label
FROM `image`
JOIN `images_tags`
ON image.id = images_tags.image_id && images_tags.tag_id IN (25,30)


Now my plan is to adjust the query so that only images are selected 
which have *all the tags assigned*, so the IN command in the ON clause 
does not fit anymore. Here is my attempt to replace the IN:


SELECT DISTINCT image.id, image.label
FROM `image`
JOIN `images_tags`
ON image.id = images_tags.image_id &&
(
    images_tags.tag_id = 25
    &&
    images_tags.tag_id = 30
)


But it doesnt´t work :(


It would be awesome if somebody could help me.

thanks a lot!

-jens

Thread
mysql query question (images,tags)Jens Kleikamp9 Nov
  • Re: mysql query question (images,tags)Jens Kleikamp9 Nov