Rohit Khurana
Rohit Khurana

Reputation: 269

how to mapping two column in sql server 2005

if someone can help me with this query. I have two tables(Searchbrain, SearchInitial) with imageid, MY idea was combine these two table according to Primarykeyword. Plz check the below table structure..

Table Structure.

Uid    Primarykeyword  ImageID 
=====  =======         =======
1      Man             123456
2      Jumping         123456
3      Beach           123456
4      Man             123457
5      Ball            123457
6      Man             123458
7      Jumping         123458
8      Beach           123458


ImageID   Color
=======   =====
123456    Red
123457    Red
123458    Red

how can i retrun these imageid(123456,123458) according to search man jumping beach..

Upvotes: 0

Views: 61

Answers (1)

podiluska
podiluska

Reputation: 51504

select ImageID 
from SearchBrain 
where Primarykeyword in ('Man','Jumping','Beach')
group by ImageID
having count(distinct Primarykeyword) = 3

(where 3 is the number of keywords)

Upvotes: 3

Related Questions