What's wrong with this SQL query?

Posted by ThinkingInBits on Stack Overflow See other posts from Stack Overflow or by ThinkingInBits
Published on 2010-05-18T05:58:09Z Indexed on 2010/05/18 6:00 UTC
Read the original article Hit count: 291

Filed under:
|
|
|

I have two tables: photographs, and photograph_tags. Photograph_tags contains a column called photograph_id (id in photographs). You can have many tags for one photograph. I have a photograph row related to three tags: boy, stream, and water. However, running the following query returns 0 rows

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

Is something wrong with this query?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about php