[PHP-DB] Delicious style Tags table

2008-09-11 Thread Catharsis
So I am having difficulty thinking of how to make this select query. I have two tables that mimic tags similar to flickr, delicious etc. They are defined below CREATE TABLE IF NOT EXISTS `taggings` ( `id` int(11) unsigned NOT NULL auto_increment, `tag_id` int(11) NOT NULL, `taggable_id`

Re: [PHP-DB] Delicious style Tags table

2008-09-11 Thread Evert Lammerts
Your 'taggings' table is basically a link table to deal with a 'many to many' relationship - i guess you know: You have a table A and a table B that have a many-to-many relationship, which is stored in table L. What query fetches all rows in A that relate to all members of the set [B1, B2, ..., Bn

Re: [PHP-DB] Delicious style Tags table

2008-09-11 Thread Catharsis
SELECT `tags`.*, count(taggable_id) as cnt, `taggings`.* FROM `tags` JOIN `taggings` ON tags.id = taggings.tag_id WHERE (name IN ('vegetarian', 'soup', 'lunch', 'curry')) group by taggable_id Evert Lammerts-2 wrote: > > Your 'taggings' table is basically a link table to deal with a 'many > to

RE: [PHP-DB] Delicious style Tags table

2008-09-11 Thread Simcha Younger
If there is only one search term - "soup" your where statement would be: Where `name` like 'soup' But you need two matches, and the terms are "soup", "vegetarian". Try: Where GROUP_CONCAT('name') like 'soup' AND GROUP_CONCAT('name') like 'vegetarian'

RE: [PHP-DB] Delicious style Tags table

2008-09-11 Thread Catharsis
Simcha Younger-2 wrote: > > If there is only one search term - "soup" your where statement would be: > Where `name` like 'soup' > > But you need two matches, and the terms are "soup", "vegetarian". Try: > Where GROUP_CONCAT('name') like 'soup' > AND GROUP_CONC

RE: [PHP-DB] Delicious style Tags table

2008-09-11 Thread Simcha Younger
I did a little testing, and this should work better: Select... From... group by taggings.id HAVING GROUP_CONCAT('name') like 'soup' AND GROUP_CONCAT('name') like 'vegetarian' Simcha Younger -Original Message- From: Catharsis [mailto:[EMAIL PROTECTED] Sent: Thursday, September 11, 2008