MySQL Select ID's which occur on different rows with multiple specific values for a column

前端 未结 5 861
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-16 20:21

I\'m trying to select items from an associative table that have satisfy two or more values of the same field, sounds confusing, let me explain.

+------------         


        
5条回答
  •  情话喂你
    2020-12-16 21:04

    I don't have the time to provide the exact query right now, but try something like this:

    select item_category.* from 
    item_category ,  item_category ic1, item_category ic2 where 
    ic1.category_id = 201 and 
    ic2.category_id = 202 and 
    ic1.item_id = ic2.item_id and 
    item_category.item_id = ic1.item_id and 
    item_category.item_id = ic2.item_id;
    

    Maybe conditions are wrong but you can try something this way.

提交回复
热议问题