Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 select question

Author  Topic 

kaisdd
Starting Member

17 Posts

Posted - 2004-11-30 : 05:33:19
i´m writing on a image database application and there is a problem where i stuck.

all the images in the database are indexed with keywords for the search function.
i have 3 tables for that. photos, keywords, keywordindex

keywordindex stores the relation between photos and keywords. each photo has as much records in the keywordindex table as it has keywords.
example:

photoID | keywordID
1__________10
1__________11
1__________12
2__________15
2__________10
3__________11
3__________20
3__________15
etc....

the problem is within the search function. if i like to search for keywordID IN (10,11) all works fine and i get photos where the keywordID is 10 or 11. but i don´t know how to write an sql select for getting photos with the keywordIDs 10 AND 11.

any suggestions.
thank you!

nr
SQLTeam MVY

12543 Posts

Posted - 2004-11-30 : 06:05:20
select photoID
from tbl
where keywordID in (10,11)
group by photoID
having count(*) = 2


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

kaisdd
Starting Member

17 Posts

Posted - 2004-12-01 : 04:26:59
thank you, works great!

i´ve noticed that i have to use "having count(*) >= n" instead of "having count(*) = n"

thank you!
Go to Top of Page
   

- Advertisement -