php - What's wrong with this SQL query? -


I have two tables: photos and photos_ tags are tagged in a photograph called "Photographed in Tag" (photo ID). You can have several tags for a photo. I have a photo line related to three tags: Boy, stream, and water, however, run the following query 0 rows

  SELECT p From the photograph P, the photo_tag C WHERE c.photograph_id = p.id and (c.value IN ('dog', 'water)', 'stream')) Group B Paid Having COUNT (PID) = 3  < / Pre> 

Is there something wrong with this query?

  My tables look like this ----------------------- Photo ---------- ------------ - ID | Title | Location ------------------------ 7 | Asdf | C: \ ... ----------------------- photograph_tags -------------------- --- ID | Photo_id | Price 1 | 7 | Dog 2 | 7 | Water 3 7 | Section 4 | 7 |  

To get all the photos with the specified 3 tags (or more), start with the tag and join the photo.

  P. From Photos Select p.id = c.photograph_id and c.value IN ('dog', 'water', 'stream') count when the group p.id (c.value)> gt; Testing code above:  
  Create table #photograph_tags (photo_id INT, value varchar (50)) #photographs (id int) # Insert in photographs values ​​(7) Insert in #photographs values ​​(8) #photograph_tags Insert values ​​(7, 'dog') Insert #photograph_tags values ​​(7, 'stream') in values ​​# 7 ('7', 'water') Insert #photograph_tags into values ​​(7, 'mountain') in the values ​​#photograph_tags (8, 'stream') # Enter value in the phototograph_tags (8, 'mountain') # from #photographs # select * # photogot_tag from #photographs Choose p.id P Skip #photograph_tags c c.photograph_id and c.value IN ( 'dog', 'water' on pid.ed, 'stream') group by PUD HW ING count (c. Value) & gt; = 3 drop table # photography_tag drop table # photographs  

Comments