我有两个表:photographs和photograph_tags。photograph_tags包含一个名为photograph_id(photographs中的id)的列。您可以为一张照片添加多个标签。我有一行照片与三个标签相关联:男孩、小溪和水。然而,运行以下查询返回0行。
SELECT p.*
FROM photographs p, photograph_tags c
WHERE c.photograph_id = p.id
AND (c.value IN ('dog', 'water', 'stream'))
GROUP BY p.id
HAVING COUNT( p.id )=3
这个查询有问题吗?
My tables look like so
-----------------------
photographs
-----------------------
id | title | location
------------------------
7 | asdf | c:\...
-----------------------
photograph_tags
-----------------------
id | photograph_id | value
1 | 7 | dog
2 | 7 | water
3 | 7 | stream
4 | 7 | mountains
I want to pull all photograph rows that relate to at least all three of the searched tags