If this is your only use case you could just have one product table with an extra "tags" column, here you could list the tags space separated then just do a full text search on that column, this would only take one query.
Thanks On Wednesday, June 30, 2010, Aurimas Likas <[email protected]> wrote: > I want to ask Im sure a really simple question (at laest for most of you). > Here is the situation: > > I have 3 DB tables: products, tags and products_tags. products_tags has 2 > columns product_id and tag_id (for many-to-many relationship). So the > question is: how can I select products which have tag1 AND tag2 and tag3 and > .... tagN? I need a best way in terms of performance. The only way I can > think of now is to create a query with self joins. The query joins number > would equal tags number - 1. Is there a better way? Maybe I miss here > something fundamental (think). My project products need a way to be filtered > by various tags... > > Thanks in advance. > -- > Aurimas L. >
