简体   繁体   中英

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..

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM