I have 3 tables, say images(id), news(id), types(id, category, obj_id, type)
For example, categories of news A are black, red.
data struct is like
{
types(xxxx1,red,news_A,news)
types(xxxx2,black,news_A,news)
}
now I need find out all images with type red and black.
In this case, I need images_B
{
types(oooo1,red,images_B,images)
types(oooo2,black,images_B,images)
types(oooo3,red,images_C,images)
types(oooo4,red,images_D,images)
types(oooo5,black,images_E,images)
}
Obviously, I can't write
select obj_id from types
where category in (select category from types where obj_id = news_A)
and type = images.
Because, like that, it will return images_B,C,D,E. I only need images_B.
Category is also dynamical. It could be red,blue,pink......