SQL查询的IN IN条件

时间:2022-06-29 15:47:58

I am having a situation like this

我有这样的情况

Select * 
from user_post 
where user_id in (select user_id from follow where follow_id=20)

This query is working fine, I need to add follow_id 20 also in the where condition... selected user_id plus this user 20 also included in the WHERE IN condition

这个查询工作正常,我需要在where条件中添加follow_id 20 ... select user_id加上此用户20也包含在WHERE IN条件中

I tried like this

我试过这样的

Select * 
from user_post 
where user_id in (select user_id from follow where follow_id=20) AND user_id=20

It did not bring the proper result

它没有带来正确的结果

the query should be like this

查询应该是这样的

Select * 
from user_post 
where user_id in (10,15,20) 

how to do this

这该怎么做

1 个解决方案

#1


SELECT
    * 
FROM 
    user_post
WHERE 
    user_id IN ((SELECT 
                    follow_id 
                FROM 
                    follow 
                WHERE 
                    follow_id=20), 10, 15);

#1


SELECT
    * 
FROM 
    user_post
WHERE 
    user_id IN ((SELECT 
                    follow_id 
                FROM 
                    follow 
                WHERE 
                    follow_id=20), 10, 15);