Using same column multiple times in WHERE clause

前端 未结 8 771
醉话见心
醉话见心 2020-12-15 10:19

I have a following table structure.

USERS

PROPERTY_VALUE

PROPERTY_NAME

USER_

8条回答
  •  再見小時候
    2020-12-15 10:38

    If I understand your question correctly I would do it like this.

    SELECT u.id, u.user_name, u.city FROM users u 
    WHERE (SELECT count(*) FROM property_value v, user_property_map m 
    WHERE m.user_id = u.id AND m.property_value_id = v.id AND v.value IN ('101', '102')) = 2
    

    This should return a list of users that have all the properties listed in the IN clause. The 2 represents the number of properties searched for.

提交回复
热议问题