Relating categories with tags using SQL

Posted by Pablo on Stack Overflow See other posts from Stack Overflow or by Pablo
Published on 2010-06-01T23:44:09Z Indexed on 2010/06/01 23:53 UTC
Read the original article Hit count: 174

Filed under:
|
|

I want be able to find tags of items under the a certain category. Following is example of my database design:

      images
      +----------+-----+-------------+-----+
      | image_id | ... | category_id | ... |
      +----------+-----+-------------+-----+
      |    1     | ... |     11      | ... |
      +----------+-----+-------------+-----+
      |    2     | ... |     12      | ... |
      +----------+-----+-------------+-----+
      |    3     | ... |     11      | ... |
      +----------+-----+-------------+-----+
      |    4     | ... |     11      | ... |
      +----------+-----+-------------+-----+

      images_tags
      +----------+--------+
      | image_id | tag_id |
      +----------+--------+
      |     1    |   53   |
      +----------+--------+
      |     3    |   54   |
      +----------+--------+
      |     2    |   55   |
      +----------+--------+
      |     1    |   56   |
      +----------+--------+
      |     4    |   57   |
      +----------+--------+

tags and categories each have their own table relating the id to an actual name(text). So my question is how will i find out that images with category_id=11 have have the tag_id 53 54 55 56 57.

In other words how to find the tags that images in certain category have?

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql