SQL: how to select a single id (“row”) that meets multiple criteria from a single column

后端 未结 9 2375
刺人心
刺人心 2020-11-30 05:38

I have a very narrow table: user_id, ancestry.

The user_id column is self explanatory.

The ancestry column contains the country from where the user\'s ancest

9条回答
  •  旧时难觅i
    2020-11-30 06:25

    one of the approach if you want to get all user_id that satisfies all conditions is:

    SELECT DISTINCT user_id FROM table WHERE ancestry IN ('England', '...', '...') GROUP BY user_id HAVING count(*) =  
    

    etc. If you need to take all user_ids that satisfies at least one condition, then you can do

    SELECT DISTINCT user_id from table where ancestry IN ('England', 'France', ... , '...')
    

    I am not aware if there is something similar to IN but that joins conditions with AND instead of OR

提交回复
热议问题